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

An issue which I can't seem to resolve, which involves part touching?

I want to make a system, inwhich you touch a part, and a GUI appears. (The part has no transparency, and has collisions off) and when you exit the part, the gui will disappear.

function appear()
print("hi")
end

function disappear()
print("bye")
end

game.Workspace.Features.Zones.zone_Airport.Touched:Connect(appear)
game.Workspace.Features.Zones.zone_Airport.TouchEnded:Connect(disappear)

(Obviously I haven't set the GUI up yet)

Any help would be appreciated.

5 comments

0

What is the output showing?

0

I think if the part has cancollide off, touches events wont fire. What you probably want is Region3. Region3 can be used to detect if a player is writhin a certain area. I wont show any example scripts but you can search youtube for tutorials on this

0

cannot collide parts still fire touched events for me

0

@testing34545 Cannot collide parts will fire touch events, but its much more clean to use region3. In this case you want to keep as much as possible in the script.

0

@Benbebop for one of my games a have the destroying barrier with cancollife off so are you saying i should check for parts in a region 3 every heartbeat?

1 answer

Server script:

local touched = game.ReplicatedStorage.TouchedEvent -- make a REMOTE function in replicated storage, if you use a different name change it here
local touchended = game.ReplicatedStorage.TouchEndedEvent -- same as above

function appear(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then -- if its a player
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player
		touched:InvokeClient(plr) -- invoke function
	end
end

function disappear(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then -- if its a player
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player
		touchended:InvokeClient(plr) -- invoke function
	end
end

game.Workspace.Features.Zones.zone_Airport.Touched:Connect(appear)
game.Workspace.Features.Zones.zone_Airport.TouchEnded:Connect(disappear)

Local script:

local pgui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local sgui = pgui:WaitForChild("ScreenGui") -- name of your screen gui
local fgui = sgui:WaitForChild("Frame") -- name of the frame to appear
local rep = game.ReplicatedStorage

rep:WaitForChild("TouchedEvent").OnClientInvoke = function() -- touched event
	fgui.Visible = true -- make visible
end

rep:WaitForChild("TouchEndedEvent").OnClientInvoke = function() -- touchended event
	fgui.Visible = false -- make invisible
end

6 comments

0

I get the error "OnClientInvoke is not a valid member of BindableFunction "ReplicatedStorage.TouchedEvent" "

0

It also spams both functions while I'm on the part.

0

oops i meant remote function

0

Hey, the script works, but while I'm moving through the part, as it has collisions off, the GUI keeps appearing and disappearing.

0

maybe add an if check to see if the part touching it is a root part because your character animation might cause several collision enters and exits

0

maybe add an if check to see if the part touching it is a root part because your character animation might cause several collision enters and exits

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