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

CFrame not working, doesn't move to right spot even with the right cframe, but no errors?

What does this script supposed to do - when a child is added in the workspace, it will check the class name of it, if its a model then it will get the player using it, then it will get the value of the stage in the leaderstats of the player then it will find a part from game.workspace.checkpoints**(folder)** that is named same as the value of the stage in the leaderstats of the player then it will get it's cframe and move the humanoidrootpart of the obj**(character)** and move it 12 studs up.

game.Workspace.ChildAdded:Connect(function(obj)
	if obj.ClassName == "Model" then
		local player = game.Players:GetPlayerFromCharacter(obj)
		local target = game.Workspace.CheckPoints:FindFirstChild(player.leaderstats.Stage.Value)
		obj.HumanoidRootPart.CFrame = target.CFrame + Vector3.new(0,12,0)
	end
end)

the error is that instead of finding the part with the name same as the value of the stage, it tries to find the STAGE in that folder

20:16:37.289 - Stage is not a valid member of Folder                                       
20:16:37.290 - Stack Begin                                                                      
20:16:37.291 - Script 'ServerScriptService.Script', Line 4                                       
20:16:37.292 - Stack End

UPDATE - i found the error, so in the script where i made the leaderstats apparently it was lowercase "s" so i made it uppercase now it works, BUT not just yet, it doesn't teleport me to the right spot, i used print to see the cframe and it was right but it still doesn't teleport me to the right spot? i tried removing the vector3 but still doesn't work.

2 comments

0

Try putting in multiple Print()'s in separate places of your script to check where does it stop working. Also playing your game through Roblox Player gives you the option to check the dev console on the client side.

0

you can use the :IsA() function instead of checking the ClassName

1 answer

✓ Accepted answer

Maybe try this

game.Workspace.ChildAdded:Connect(function(char)
	if char:IsA("Model") then
		local stage = player.leaderstats:WaitForChild("Stage").Value
		local target = workspace.CheckPoints:FindFirstChild(stage)
		char.HumanoidRootPart.CFrame = target.CFrame + Vector3.new(0,12,0)
	end
end)

1 comment

0

I don't know how that worked but it did :D, thankyou

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