Hello, I’m rexhawk. I’ve recently started development on a game with a friend and I’ve run across a brick wall.
My ultimate goal is to make it so that as you look around, your client searches every object you’re focusing on and determines if it is an interactive object by searching if a folder exists within the object (if that makes sense).
Once it determines that the object is, in fact, interactive, it checks if you’re close enough to the object (the radius) and if so, it’ll give you a tooltip.
I’ve done this with the following code, but it then starts to act weird. The GUI enables, but as I walk away while focusing on the object, it doesn’t disable until I look away. This is weird because it’s supposed to recalculate if the player is within range of the object with every step.
example of this behavior:
Any help with this would be a tremendous help!
Code:
--<< Enable Tooltip
mouse.Move:Connect(function()
if mouse.target then
if mouse.target.Parent:FindFirstChild("Settings") then --<< It is a interactable object
if (player.Character.HumanoidRootPart.Position-mouse.target.Position).magnitude <= mouse.target.Parent.Settings.interact.distance.Value then --<< in range
--<< In range, enable tooltip
player.PlayerGui:WaitForChild("Core").Cursor.Text = mouse.target.Parent.Settings.interact.tooltip.Value
end
else
player.PlayerGui:WaitForChild("Core").Cursor.Text = ""
end
else
player.PlayerGui:WaitForChild("Core").Cursor.Text = ""
end
end)
player.Character.Humanoid.Running:Connect(function()
if mouse.target then
if mouse.target.Parent:FindFirstChild("Settings") then --<< It is a interactable object
if (player.Character.HumanoidRootPart.Position-mouse.target.Position).magnitude <= mouse.target.Parent.Settings.interact.distance.Value then --<< in range
player.PlayerGui:WaitForChild("Core").Cursor.Text = mouse.target.Parent.Settings.interact.tooltip.Value
end
else
player.PlayerGui:WaitForChild("Core").Cursor.Text = ""
end
else
player.PlayerGui:WaitForChild("Core").Cursor.Text = ""
end
end)