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

Glowstick shop gui does not reappear after touching part again?

Asked by 4 years ago

I've recently made a script that is placed into a part. The script is supposed to make it so whenever you touch the part with your character it enables the visibility of a gui that every player starts out with. I'd also like to note that the gui's visibility is set to false by default. The script works as planned the first time but when I close the gui and touch the part again it does not reappear like I want it to. The gui has a "close" button that just sets the visibility back to false so It should be reappearing when touching the part again. Here is the script:

local Part = script.Parent
Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then 
        local Player =game.Players:GetPlayerFromCharacter(HIT.Parent)
        Player.PlayerGui.Glowsticks.Frame.Visible = true
    end

end)

Here is the close button localscript inside the gui:

function onButtonClicked()
script.Parent.Parent.Visible = false
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

1 answer

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

Try firing a remote event for a client that touches the part and get the player by that event.

Or to be more precise:

local Part = script.Parent
Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then 
        local Player =game.Players:GetPlayerFromCharacter(HIT.Parent)
        game.ReplicatedStorage.RemoteEvent:FireClient(Player) --Fire this event on touch
    end

end)

In Localscript:

plr = game.Players.LocalPlayer

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
--plr is the player that touched the part.
plr.PlayerGui.Glowsticks.Frame.Visible = true
end)

function onButtonClicked()
script.Parent.Parent.Visible = false
end

script.Parent.MouseButton1Click:connect(onButtonClicked)


0
What do you mean? User#34929 0 — 4y
0
Nvm my page wasnt loaded I didnt see your edit OVOFinessinq 21 — 4y
0
oh ok User#34929 0 — 4y
0
Any progress? User#34929 0 — 4y
View all comments (7 more)
0
Doesnt seem to be working for me. I made a remote event and named it "GlowstickEvent", renamed it in the scripts aswell and it isnt working OVOFinessinq 21 — 4y
0
Whats the error? User#34929 0 — 4y
0
Players.Dxligent.PlayerGui.Glowsticks.Frame.Close.LocalScript:2: attempt to index nil with 'PlayerGui' OVOFinessinq 21 — 4y
0
try the edited version User#34929 0 — 4y
1
Works Great! Thanks for the help. Ill make sure to accept your answer OVOFinessinq 21 — 4y
0
Thanks! User#34929 0 — 4y
0
The issue was that he was setting the visibility to false on the client, whilst the visibility was still set to true on the server. So when he touched the part again, it didn't set it to true for him, even though it was set to false on his client, but on the server it was still set to true. This also could've been fixed by changing the local script in the button to a server script. xInfinityBear 1777 — 4y
Ad

Answer this question