I'm new to scripting and I am trying to make a teleportation script, but I don't know how to reach the character on line 19. It says, "Head is not a valid member of Workspace." Please help.
button = script.Parent.buttonframe.TextButton gui = script.parent.Frame telebutton = gui["tele to red"] platform = game.Workspace.teleplatform gui.Visible = false button.MouseButton1Down:connect(function() if gui.Visible == false then gui.Visible = true else gui.Visible = false end end) telebutton.MouseButton1Down:connect(function() if gui.Visible == true then game.Workspace.Head.CFrame = target.CFrame*CFrame.new("-16.139, 4.048, 42.141") end end)
If you didn't know, there is a function called WaitForChild()
. What this function does is it will wait for the child (The items inside of the item) to load.
This method is commonly used to get a part from a character.
Here's some examples.
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local Character = player.Character or player.CharacterAdded:Wait() local Head = character:WaitForChild('Head')
This way, you can ask the script to wait for the object inside of something.
I hope you learned something today! Have a nice day! ;)