Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why isnt the teleport script working?

Asked by 2 years ago

when a button is clicked on the gui i need the player to tp to a location

heres the local script under the button:

script.Parent.MouseButton1Click:Connect(function() local locationofred = game.Workspace.RedSpawn.CFrame game.ReplicatedStorage.Teleporter:FireServer(locationofred) end)

here is the server script after the event is fired:

game.ReplicatedStorage.Teleporter.OnServerEvent:Connect(function(player, location) local playerlocation = player.Character.HumanoidRootPart.CFrame local partlocation = location playerlocation = CFrame.new(partlocation) end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Hello,

the problem is the following:

local playerlocation = player.Character.HumanoidRootPart.CFrame

When storing the CFrame of the HumanoidRootPart, you actually created a copy rather than a reference to the CFrame. Instead, you should just write your function like this:

game.ReplicatedStorage.Teleporter.OnServerEvent:Connect(function(player, location)
    player.Character.HumanoidRootPart.CFrame  = location
end)

Also, setting the CFrame by object.CFrame = CFrame.new(otherObject.CFrame) does not work because the .new keyword is there to create a new CFrame object with the first argument as a Vector3 (or alternatively, three number values).

Hope this helps.

0
Also take note of the way I set the CFrame KochbananemitGuave 15 — 2y
0
Bro thanks so much it finally works now! Younes_wldn 4 — 2y
0
No problem bro KochbananemitGuave 15 — 2y
Ad

Answer this question