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

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

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

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)

2 comments

0

No I want to access the actual player. Still, after fixing it and getting rid of that line, it didn't work.

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.

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

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