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

The Script works in studio but not in-game? Possible fix?

Asked by 6 years ago

Is there a possible fix for this? I don't understand why this is not working :/ It works in studio but not in game...

ScreenGui > TextButton > LocalScript

LocalScript Below.

Character = game.Players.LocalPlayer.Character
torso = Character.Torso

function onClicked(ScreenGui)
    torso.CFrame = CFrame.new(Vector3.new(-131.7, 9.3, -30.85)) -- Coordinates
end

script.Parent.MouseButton1Click:Connect(onClicked)
0
Thanks I'll take a look TheForgottenTale 23 — 6y
0
In the past, when I tried to change the position of the player in a local script the server still saw the player in his original location. It was quit strange. Bluemonkey132 194 — 6y

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Make your variables local and use WaitForChild() on your Torso.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
local torso = Character:WaitForChild("Torso")
function onClicked()
    torso.CFrame = CFrame.new(-131.7, 9.3, -30.85) -- Coordinates
end

script.Parent.MouseButton1Click:Connect(onClicked)
Ad

Answer this question