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

Why will this script only work in studio test mode?

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

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

4 comments

0

Doesn't work :(

0

There was a typo, lol. Line 3, at the end, supposed to be :wait(), not :wair()

0

Still doesn't work

0

":LoadCharacter()" doesn't work in local scripts.

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