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

The part won't face the player like I want it to, but no errors?

Asked by 10 years ago

Basically, I have a script and a BodyGyro in a part. The part is not anchored or cancollide, but it has a BodyPosition object to hold it in place. What I want to do is have the part always face the player (I'm going to make it a local part so each player sees it face them, but that's later). However, whenever I run the script in solo, it does not make the object face the player, but throws no errors. Why is this?

game.Players.PlayerAdded:connect(function(plr)
    while plr do
        wait()
        player = game.Players:GetPlayerFromCharacter(plr)
        if player then
            script.Parent.BodyGyro.cframe = CFrame.new(player.HumanoidRootPart.Position)
        end
    end
end)

Thank you for any feedback, advice, or changes you have.

2 answers

Log in to vote
0
Answered by 10 years ago

This is incorrect in a way that first, the "GetPlayerFromCharacter" isn't needed, because the player is "plr", if you want the character, say "player = plr.Character". The correct should be:

game.Players.PlayerAdded:connect(function(plr)
    while plr do
        wait()
        player = plr.Character
        if player then
        script.Parent.BodyGyro.CFrame = CFrame.new(player.HumanoidRootPart.Position)
end
end
end)
0
No I want to access the actual player. Still, after fixing it and getting rid of that line, it didn't work. Ulrakid11 5 — 10y
0
After testing the original script with print commands, it finds plr but never reaches player. It can't find the player from the character. Ulrakid11 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Does anyone have a solution? This has been bothering me for quite some time.

Answer this question