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

How to teleport player when Gui button clicked??

Asked by 2 years ago

Hi I have a Gui button that I want the player to teleport to a part when click. But it doesn't work. I have tried putting the teleport script in the Gui button. It didn't work so I tried to send a remote event to severscriptservice to teleport the player still don't work. The remote event is named TP and the scripts are just scripts. Gui button script:

script.Parent.MouseButton1Click:Connect(function(player)



    game.ReplicatedStorage.TP:FireClient()



end)

ServerScriptService Script:

game.ReplicatedStorage.TP.OnServerEvent:Connect(function(player)

    player.Character.HumanoidRootPart.Position = workspace.CarSpawnPlayer.Position  

end)

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago
player.Character.HumanoidRootPart.CFrame = workspace.CarSpawnPlayer.CFrame  

you need to use CFrame when moving humanoids because they have all these Motor6Ds and attachments, joints, moving Position won't update the constraints which will kill the humanoid i think or just won't move it... also you have a typo i guess:

game.ReplicatedStorage.TP:FireClient()
-- ^^^ noe
game.ReplicatedStorage.TP:FireServer()

i don't know for sure but i think you don't even need the remote event since specially applies to humanoid, moving humanoid locally will replicate it to all other players automatically.

0
Hi I did all the fixes you suggested I keep receiving an error error code: FireServer can only be called from the client. theking66hayday 841 — 2y
0
Oh crap hi Kirda CDXKIE 130 — 2y
0
???? theking66hayday 841 — 2y
0
the script in the button must be localscript!!!!!!!!!!!!!!!!!!!!!!!!!!! imKirda 4491 — 2y
0
Thank you this helps me a lot!! theking66hayday 841 — 2y
Ad

Answer this question