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

My GUI is popping up even when the touch function isn't running?

Asked by 3 years ago
Edited 3 years ago

I'm making a police-criminal game like Jailbreak, and I'm making the part where when you escape it prompts you with an escape GUI to let you know.

The problem is, the event's running even if I don't touch the part where you escape

LocalScript in The GUI text label:

local Player = game:GetService("Players").LocalPlayer
local Prisoner = game.Teams.Prisoners

game.Workspace.CrimWall.Touched:Connect(function()
    if Player.Team == Prisoner then 
    script.Parent.Parent.Visible = true
    script.Parent.Visible = true
    wait(5)
    script.Parent.Parent.Visible = false
    script.Parent.Visible = false
        end
end)

NOTE THAT: THE REASON ISN'T BECAUSE IT'S TOUCHING SOMETHING ELSE, THE GUI COMES WHEN YOU PASS A POINT, BUT NOTHING IS AT THAT POINT, ITS NOT EVEN ANYTHING UNIONED, AND THE GUI IS COMING UP

1
Something else may be touching the wall, you can add a check to see if they are aplayer or not. JustinWe12 723 — 3y
0
its like you pass a point and then it happens, but that point isnt the thing SuperSM1 67 — 3y
0
It doesn't have to be a player touching the wall. Any basepart in your experince could trigger the function. JustinWe12 723 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Check if the touching instance is within the player's character hierarchy.

local Player = game:GetService("Players").LocalPlayer
local Prisoner = game:GetService("Teams"):WaitForChild("Prisoners")

workspace.CrimWall.Touched:Connect(function(hit)
    if hit and Player.Character and hit:IsDescendantOf(Player.Character) then
        if Player.Team == Prisoner then 
            script.Parent.Parent.Visible = true
            script.Parent.Visible = true
            wait(5)
            script.Parent.Parent.Visible = false
            script.Parent.Visible = false
        end
    end
end)
0
didnt work SuperSM1 67 — 3y
0
nevermind it worked, thanks dude SuperSM1 67 — 3y
Ad

Answer this question