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

This simple code won't change the torso's CFrame, why?

So, I'm trying to change a torso's CFrame if a value in the character equals 1. I made a separate DataStore that saves the value, and it works just fine, this CFrame thing is the only problem. I got no errors in Studio and when I checked the dev console there were still no errors.

Here's the code I used: LOCAL SCRIPT

local player = game.Players.LocalPlayer

if player.JAILED.Value == 1 then
	game.ReplicatedStorage.JailedPersonEvent:FireServer()
end

player.Character.Humanoid.Died:Connect(function()
	if player.JAILED.Value == 1 then
		game.ReplicatedStorage.JailedPersonEvent:FireServer()
	end
end)

SERVER SCRIPT

game.ReplicatedStorage.JailedPersonEvent.OnServerEvent:Connect(function(player)
	local character = game.Workspace:WaitForChild(player.Character)
	
		character.Torso.CFrame = CFrame.new(1717.323, 226.31, -1283.756)
	
end)

Any reason why???

1 answer

✓ Accepted answer

On line 2 of your server script, you said:

local character = game.Workspace:WaitForChild(player.Character)

There's no point in saying that because if player.Character didn't load, then you are searching for nil.

Replace it with:

local character = player.Character or player.CharacterAdded:Wait()

Hope this helps :)

1 comment

0

Line 2 would error if a player named Part joined the game LOL

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