Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to teleport player when he clicks a button?

i have problems with this gui a lot so i will tell everything about it. i am making a warning gui when players coin leaderstats reach a certain amount and you use a toll to gain coins. I have a script in coins which fires a remote event which is in replicated storage and its picked up by this script. here are things you should know my gui is in starter gui all buttons have local scripts

game.ReplicatedStorage.coinsEvent.OnServerEvent:connect(function(player)
if player.leaderstats.coins.Value = player.Capacity.Value then
        player.PlayerGui.Warning.Frame.Visible = true
   end
end)

this part works but i think i should tell this because i think that server thinks that gui is not on from the server side so it dosent pick up when buttons in that gui are clicked cuz they are just on from client side. Anyways there are two buttons in the gui close and shop. My close script works so i will not mention it and here is the main problem

shop script

player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
          player.Character.Humanoid.CFrame = CFrame.new(--shop positions)
end)

this do not teleport the player when he clicks the button plz help

1 answer

You shouldn't make changes to instances from the client side unless it is something like a GUI. In the 2nd script you moved the player from a local script so the changes will only take place on their screen. You should use a remote event and receive the event with a script in the ServerScriptService. Also it might be better to use another event and send from the server to the client, in which the client can receive this event and change the warning frame to visible. one last thing, that's not the proper way to teleport the player, you were close but not quite. So the humanoid contains all the stats of the player's character and has no actual physical representation. You need to change the CFrame of the HumanoidRootPart. Read about Remote events here

2 comments

0

use this explanation it's better @typhoon1421

0

also u didnt explain when he tried to move the humanoid which u couldnt!

This discussion is preserved as it was. New answers, comments, and votes are closed.