So I made this script and I inserted it to Workspace > Part > SurfaceGui > TextButton I need it to teleport me to a brick "SpawnLocation1", but when I clicked the SurfaceGui TextButton, it did nothing, please help
spawn = game.Workspace.SpawnLocation1 player = script.Parent.Parent.Parent.Parent function onClicked() player.Character:MoveTo(spawn.Position) end script.Parent.MouseButton1Down:connect(onClicked)
When I clicked it, it didn't work. I saw this error in the output, I'm a newbie scripter so I don't know what how Character is not a valid member of Workspace.
19:54:47.303 - Character is not a valid member of Workspace 19:54:47.305 - Script 'Workspace.Part.SurfaceGui.TextButton.Script', Line 5 19:54:47.307 - Stack End
I have no idea how to fix this.
Well, to correct that error, you'd put a LocalScript in StarterGui and put the SurfaceGui itself (NOT the brick) in StarterGui. Then, with the following scripts, you'll be able to access the player.
If you just put it in StarterGui, it's not going to be on the brick. This is where some scripting jumps in. Put this as a LocalScript in StarterGui
repeat wait() until game.Players.LocalPlayer.PlayerGui game.Players.LocalPlayer.PlayerGui["GUI Name Here"].Adornee = game.Workspace.Part -- Define the path to the part where it's supposed to appear on. You may want to change the Part's name, so it doesn't get mixed up with other parts.
After you've done that, in the button, put the following:
spawn = game.Workspace.SpawnLocation1 function onClicked() player = game.Players.LocalPlayer player.Character:MoveTo(spawn.Position) end script.Parent.MouseButton1Down:connect(onClicked)
Any questions? Make sure to comment.
--Not sure if this will work but, Make it a LOCAL script.
spawn = game.Workspace.SpawnLocation1 player = game.Players.localPlayer script.Parent.MouseButton1Down:connect(function() wait() player.Character:MoveTo(spawn.Position) end)