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

How do I know if the player is close to something without multiple if statements?

    HumanoidRootPartWait = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

  

Coal = workspace.Coal

Stick = workspace.Sticks

HumanoidRootPart = game.Players.LocalPlayer.Character.HumanoidRootPart

LocalPlayer = game.Players.LocalPlayer

while wait(1) do

if (HumanoidRootPart.Position - Stick.Position).Magnitude < 10 or (HumanoidRootPart.Position - Coal.Position).Magnitude < 10 then

LocalPlayer.PlayerGui.ScreenGui.Enabled = true

else

LocalPlayer.PlayerGui.ScreenGui.Enabled = false

end

end

  

  

  

  

LocalPlayer.PlayerGui.ScreenGui.TextButton.Activated:connect(function()

end)

Is there a way to know which object the player is close to? Sticks or coal in this place, without having multiple if statements to check what it is close to.?

1 answer

You could have a 'hitbox' and detect if that's touched, and use a remoteevent to enable it using 'FireClient'. I do not know any other way.

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