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

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

Asked by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago

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.

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. Tymberlejk 143 — 5y
0
you can use the :IsA() function instead of checking the ClassName User#23365 30 — 5y

1 answer

Log in to vote
1
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
I don't know how that worked but it did :D, thankyou CjayPlyz 643 — 5y
Ad

Answer this question