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

Glowstick shop gui does not reappear after touching part again?

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

✓ Accepted answer

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)


11 comments

0

What do you mean?

0

Nvm my page wasnt loaded I didnt see your edit

0

oh ok

0

Any progress?

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

0

Whats the error?

0

Players.Dxligent.PlayerGui.Glowsticks.Frame.Close.LocalScript:2: attempt to index nil with 'PlayerGui'

0

try the edited version

1

Works Great! Thanks for the help. Ill make sure to accept your answer

0

Thanks!

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.

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