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

Why does my script work in studio, but not in an actual server?

My script works perfectly when I test it in studio. Though for some reason, when I go to play the game, it doesn't work.

The script is in a screen GUI button that teleports me to a location within the game.

button = script.Parent
player = game.Players.LocalPlayer
torso = player.Character.Torso

function toOffice()
	torso.CFrame = game.Workspace.Teleport.CFrame
end

button.MouseButton1Click:connect(toOffice)

3 comments

0

I assume this is a local script right?

1

Yes it is

0

Like in the common mistakes, it states that Play Solo and the regular roblox launcher is TWO DIFFRENT things.

2 answers

✓ Accepted answer

Because you have to wait for the character to load.

button = script.Parent
player = game.Players.LocalPlayer
repeat wait() until player.Character.Torso
torso = player.Character.Torso

function toOffice()
    torso.CFrame = workspace.Teleport.CFrame
end

button.MouseButton1Click:connect(toOffice)

still a localscript and it works in the game this way. good luck

button = script.Parent
player = game.Players.LocalPlayer
torso = game.Workspace:WaitForChild(player.Name).Humanoid.Torso

function toOffice()
    torso.CFrame = game.Workspace.Teleport.CFrame
end

button.MouseButton1Click:connect(toOffice)

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