Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this touch event disappear whenever another player enters the area?

Asked by
gitrog 326 Moderation Voter
6 years ago

So, I have a huge invisible brick with CanCollide off around an area, and it's supposed to show the player a gui while they're in that area. However, whenever someone else enters the area, it removes the gui for anyone currently in the area. Any help?

--Hide the indicator
script.Parent.Transparency = 1


--The indicator was touched
script.Parent.Touched:connect(function(touching)
    --Check if the part is part of a player
    local player = game.Players:GetPlayerFromCharacter(touching.Parent)

    if player then
        --If the gui doesn't exist, make the gui
        if player.PlayerGui:FindFirstChild("gangTurf") == nil then
            local gui = game.ServerStorage.GuiStore.gangTurf:Clone()
            gui.Parent = player.PlayerGui
            script.Parent.TouchEnded:connect(function(newTouch)
                --If the part that disconnected was from the receiving player, then remove the gui.
                --Prevents weird flashing of the gui.
                local checkPlayer = game.Players:GetPlayerFromCharacter(newTouch.Parent)
                if checkPlayer == player then
                    gui:Destroy()   
                end
            end)
        end
    end
end)
0
What you could do to prevent the flashing of the gui by using debounce saSlol2436 716 — 6y
0
You could save time and use magnitude. LastApollo 76 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
while true do
    for i,v in pairs(game.Players:GetChildren()) do
        repeat wait() until v.Character
        if (v.Character.HumanoidRootPart.Position - game.Workspace["PART"].Position).magnitude <= 10 then --Put the distance from which the player should start seeing the GUI
            GUI.Visible = true
        end
    end
wait()
end

Make sure to run through my script for errors, and make sure to locate the GUI and part from where they are located in your editor.

I HIGHLY ADVISE YOU TO ASK ME ANYTHING IF YOU RUN INTO PROBLEMS!!!

Ad

Answer this question