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

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

Asked by 4 years ago
Edited 4 years ago

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

0
local Distance = (Part.Position - Compare.Position).Magnitude Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
0
Oh! I'm sorry I missed that. My bad! DiamondMiner199 30 — 4y
Ad

Answer this question