✓ Accepted answer
Good day, hope you are doing well.
Basically, I think the issue is happening because you are connecting the touch event to the brick itself. This means that the event fires, when anybody touches the brick.
Instead, you have to check if that individual player touched that brick.
script.Parent.Frame.Visible = false
local brick = workspace.Shop
local player = game.Players.LocalPlayer
local debounce = false
brick.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid.Parent.Name == player.Name then
if debounce == false then
debounce = true
script.Parent.Frame.Visible = true
end
end
end
end)
brick.TouchEnded:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid.Parent.Name == player.Name then
if debounce == true then
debounce = false
script.Parent.Frame.Visible = false
end
end
end
end)
I tried replicating this scenario in Roblox Studio, and this is what worked for me. The debounce variable is optional, but I would keep it to yield more accurate results and for performance.
1 comment
Yes that worked, but I had to remove the 'local' on line 06 for it to work.