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

How can I only activate a chat-activated function when they are close enough?

I have an easter egg with a text label that will only show up when the player is close enough to the Part. I've tried getting the distance, but either I'm using the wrong thing entirely or there's a minor error in there. But mostly the thing I can't seem to figure out is how to get the position of the player, as it says that HumanoidRootPart is not a valid member of player.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "message" and player.HumanoidRootPart.Position - workspace.TreeSecret.Trunk <= 10 then
			script.Parent.SurfaceGui.TextLabel.Visible = true
			wait(0.5)
			script.Parent.SurfaceGui.TextLabel.Visible = false
		end
	end)
end)

Thanks

1 comment

0

local Distance = (Part.Position - Compare.Position).Magnitude

1 answer

✓ Accepted answer

HumanoidRootPart is not a member of player, but rather of Character To find HumanoidRootPart from player, you can define it like this:

player.Character.HumanoidRootPart

1 comment

0

Oh! I'm sorry I missed that. My bad!

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