I’m trying to make a pad that when a player steps on it it glows then when they get off it’s dull I was able to do it with touched and touch ended events but it’s buggy sometimes the characters animation would trigger an on and off visual anyone have any alternatives?
add two touch detectors so one on the outside what detects when they leave the pad and one when the player steps on it
In this scenario, using simply .Touched
events will not be what you need. To make it work, you will need to use a spatial query, which sounds complex but is just a phrase that means “check if something exists in a space”.
I don’t have much context from your post, but I will try my best to answer.
The query workspace:GetPartBoundsInBox()
checks if something exists in an area defined by a box.
So, for example:
local Pad = workspace.QueuePad
task.spawn(function()
while true do
local QueryResults = workspace:GetPartBoundsInBox(
Pad.CFrame * CFrame.new(0, 3, 0), -- The position of the "box", using a CFrame
Vector3.new(5, 5, 5) -- The size of this "box"
-- You can use an OverlapParams object to further filter down your results.
-- This is more useful for situations like combat scripts, for example, for here we don't need it.
)
if QueryResults then -- Sometimes, spatial queries will return nil, so check if it's not nil first!
for i, v in pairs(QueryResults) do
-- From here, check if any characters exist.
if v and v.Parent then
if v.Parent:FindFirstChildOfClass("Humanoid") then
-- It's a character!
Pad.Material = Enum.Material.Neon
break -- Leave the for loop we made.
end
end
end
-- If the loop wasn't broken, just set the material to something dull.
Pad.Material = Enum.Material.Glass -- Glass looks good for this.
end
task.wait(0.05) -- this isn't necessary something to check very often
-- so it's fine to check only every 1/20 of a second.
end
end)