Reputation: 11
So, I have been trying to make a game with multiple enemies. Now, those enemies, they are caged in a cage far from the Baseplate. I made a ProximityPrompt inside a part which is transparent and have CanCollide off which if triggered will teleport you to the position of another transparent part which is inside the cage. I have been researching on how to do this. I put this code on a LocalScript in the ProximityPrompt:
local teleportPart = game.Workspace.TELEPORT.Position
script.Parent.Triggered:Connect(function()
game.Players.LocalPlayer.Character:MoveTo(teleportPart)
end)
-- TELEPORT is the transparent part in the cage.
Then, I tested it. However, when the ProximityPrompt is triggered, nothing happens. No errors in the command bar, nothing.
I tried multiple ways such as:
game.Players.LocalPlayer.Character:MoveTo(teleportPart)
to Character.HumanoidRootPart.CFrame = CFrame.new(2350.5, -6.2, 639.015)
game.Players.LocalPlayer.Character:MoveTo(game.Workspace.TELEPORT.Postion)
game.Players.LocalPlayer.Character:MoveTo(teleportPart.Postion)
)None have worked, none have errors. What should I do? Thanks.
Upvotes: 1
Views: 531
Reputation: 7188
Your code and all of your previous attempts look fine, but your issue is that LocalScripts only execute from a handful of locations. According to the documentation :
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
- A Player's Backpack, such as a child of a Tool,
- A Player's character model,
- A Player's PlayerGui,
- A Player's PlayerScripts,
- The ReplicatedFirst service.
Since your LocalScript is the child of a ProximityPrompt in the Workspace, it simply never executes.
So to fix your issue, convert your LocalScript to a Script and try this. You can get the Player who activated the prompt as an argument from the Triggered event :
local proximityPrompt = script.Parent
local teleportPart = game.Workspace.TELEPORT
proximityPrompt.Triggered:Connect(function(player)
local character = player.Character
if character then
character:MoveTo(teleportPart.Position)
end
end)
Upvotes: 2