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

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

Asked by 3 years ago
Edited 3 years ago

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.

0
What is the output showing? Soban06 410 — 3y
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 JeffTheEpicRobloxian 258 — 3y
0
cannot collide parts still fire touched events for me testing34545 12 — 3y
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. Benbebop 1049 — 3y
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? testing34545 12 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
I get the error "OnClientInvoke is not a valid member of BindableFunction "ReplicatedStorage.TouchedEvent" " IrishRepubIic 9 — 3y
0
It also spams both functions while I'm on the part. IrishRepubIic 9 — 3y
0
oops i meant remote function testing34545 12 — 3y
0
Hey, the script works, but while I'm moving through the part, as it has collisions off, the GUI keeps appearing and disappearing. IrishRepubIic 9 — 3y
View all comments (2 more)
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 testing34545 12 — 3y
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 testing34545 12 — 3y
Ad

Answer this question