What do you want to achieve? I want to make a GUI frame show up when the player touches a part but I also want the GUI frame to disappear when the player isn’t touching the part.
What is the issue? When the player touches the part the GUI frame shows up but then it just disasters when the player is still touching the part.
What solutions have you tried so far? I looked on this devforum to find other people who had the same problem and had a solution.
Does anyone have any ideas what going on? I checked to see if there anything wrong with the GUI side to see if there anything making the frame disappear but there nothing there.
Garden.Hitbox.Touched:Connect(function(Other_Part) – This is part of the code
if Other_Part.Parent:FindFirstChild("Humanoid") and Other_Part.Parent.Name == Plr.Name then
Garden_Events.Garden_Menu:FireClient(Plr, true) -- Tells the client side to make the GUI Frame visible
end
end)
Garden.Hitbox.TouchEnded:Connect(function(Other_Part)
if Other_Part.Parent:FindFirstChild("Humanoid") and Other_Part.Parent.Name == Plr.Name and Other_Part then
Garden_Events.Garden_Menu:FireClient(Plr, false) -- Tells the client side to make the GUI frame to disappear
end
end)
local part = workspace.Part -- or path to part
local limbs = table.create(game.Players.MaxPlayers)
part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
-- limb of player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if limbs[player] then
table.insert(limbs[player], hit)
else
limbs[player] = {
hit,
}
-- do stuff for first limb touched
end
end
end)
part.TouchEnded:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
-- limb of player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if #limbs[player] == 1 then
limbs[player] = nil
-- do stuff for last limb untouched
else
table.remove(limbs[player], table.find(limbs[player], hit))
end
end
end)
local event = game.ReplicatedStorage:WaitForChild("GuiEvent")
local hitbox = script.Parent
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
event:FireClient(player, true)
end
end
end)
part.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
event:FireClient(player, false)
end
end
end)
Local Script (Put in StarterGui)
local Frame = script.Parent.Frame
local event = game.ReplicatedStorage:WaitForChild("GuiEvent")
event.OnClientEvent:Connect(function(vis)
Frame.Visible = vis
end)
Your gui appears and disappears as any limb touches the part which can give unexpected results, that code makes it so when the first limb touches you can run code and when the last limb untouches you can clean it up.
Is this what is occuring to you when you’re trying my code or are you talking about your last code? Could you show the updated code if you’re talking about mine.