Skip to content

Instantly share code, notes, and snippets.

@elevenpassin
Last active September 28, 2021 05:43
Show Gist options
  • Save elevenpassin/5c3559c4be573431608e0ffb2e65a816 to your computer and use it in GitHub Desktop.
Save elevenpassin/5c3559c4be573431608e0ffb2e65a816 to your computer and use it in GitHub Desktop.
Player sensitive interactables

Interactables in ROBLOX

Setups up interactables in a video game based on player distance from the object. Useful for showing "interact" buttons on anything from doors to cars etc.

local Interactables = game.Workspace.Interactables:GetChildren()
local CharacterRoot = script.Parent.HumanoidRootPart
local RunService = game:GetService("RunService")
local current = nil
for _, interactable in pairs(Interactables) do
local routine = coroutine.create(function(part1, part2, distance)
RunService.Stepped:Connect(function()
local d = (part1.Position - part2.Position).Magnitude
if d < distance then
if current then
current.BillboardGui.Enabled = false
end
current = interactable
else
interactable.BillboardGui.Enabled = false
end
if current then
current.BillboardGui.Enabled = true
end
end)
end)
coroutine.resume(routine, interactable, CharacterRoot, 10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment