Hey!
I have a local script to open a certain GUI when a player stands on a part, but the problem is, I don’t know how to make it disappear when he’s not on the part. Any ideas?
Thanks in Advance!
For more information just ask me in the comments…
Hey!
I have a local script to open a certain GUI when a player stands on a part, but the problem is, I don’t know how to make it disappear when he’s not on the part. Any ideas?
Thanks in Advance!
For more information just ask me in the comments…
there is a function called TouchEnded you can use it on that part and using a debounce it should work perfectly example
workspace.Part.TouchEnded:Connect(function()
-- do stuff
end)
does it give the “hit” parameter tho?
nvm it does, ty!
yes it does anything to do with touched does
Hey, it works but is there a way to fix this twitch effect?
try adding a debounce if not then make a simple part around it
TouchEnded is unreliable (lots of problems with it here), this may be why you have a twitching effect as perhaps Touched fires even though the player hasn’t ended touching it.
You can create an alternative, use the Zones module, or read this.
I’d personally use .Magnitude
with RunService
rather than touched events, as it’s more stable and you don’t have to worry about that occurring - and as @Mewious, a debounce would be useful for these scenarios, but for my code it’s not really necessary. An example would be:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function()
local toCompare = (char:WaitForChild("HumanoidRootPart").Position - game.Workspace.YOUR_PART.Position).Magnitude
if toCompare <= 3 then
plr.PlayerGui.UI_STUFF.Visible = true
else
plr.PlayerGui.UI_STUFF.Visible = false
end
end)
-- localscript in StarterPack