Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

1

Something else may be touching the wall, you can add a check to see if they are aplayer or not.

0

its like you pass a point and then it happens, but that point isnt the thing

0

It doesn't have to be a player touching the wall. Any basepart in your experince could trigger the function.

1 answer

✓ Accepted answer

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)

2 comments

0

didnt work

0

nevermind it worked, thanks dude

This discussion is preserved as it was. New answers, comments, and votes are closed.