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

Why will this script only work in studio test mode?

Asked by
shasta 0
9 years ago

This script works perfectly in studio put in-game, it doesn't do anything. Please help.

plr = game.Players.shasta
mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == "t" then
        if plr ~= nil then
            local pos = plr.Character.Torso.Position
            plr:LoadCharacter()
            plr.Character.Torso.CFrame = CFrame.new(pos)
        end
    end
end)

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago

Hopefully, you are using a localscript. You should make a variable defining the character since when a player joins, their character is initially set to nil. Also, idk if you want localPlayer or specifically you.

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
char = plr.Character or plr.CharacterAdded:wair()

mouse.KeyDown:connect(function(key)
    if key == "t" then
        if plr ~= nil then
            local pos = char:WaitForChild("Torso").Position
            plr:LoadCharacter()
            char.Torso.CFrame = CFrame.new(pos)
        end
    end
end)

Although, I am not certain if this will work since you are loading the character and then setting the CFrame of the torso. The PlayerGui is cleared upon player respawn so this script might be removed. In the future, use UIS to handle keyboard input and such

0
Doesn't work :( shasta 0 — 9y
0
There was a typo, lol. Line 3, at the end, supposed to be :wait(), not :wair() SurVur 86 — 9y
0
Still doesn't work shasta 0 — 9y
0
":LoadCharacter()" doesn't work in local scripts. Redbullusa 1580 — 9y
Ad

Answer this question