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

Script will not repeat when called?

I'm making a shop where if you touch a part it enables the GUI and the X button disables. It works fine but if I try it a second time it doesn't work. Here's the code:

Part enabler (server script):

local part = script.Parent

part.Touched:Connect(function(parthit)
	print("fired")
	local gui = game.Players[tostring(parthit.Parent.Name)].PlayerGui:WaitForChild("TrailShopGUI")
	gui.Enabled = true
end)

X button (local script):

local button = script.Parent

button.MouseButton1Click:Connect(function()
	local gui = script.Parent.Parent.Parent
	gui.Enabled = false
end)

Any help is appreciated!

1 answer

✓ Accepted answer

It don't works because if the value is the same you're trying to set, the server don't replicates the change, as its already that value, what you can do is changing the value before setting:

local part = script.Parent

part.Touched:Connect(function(parthit)
    print("fired")
    local gui = game.Players[tostring(parthit.Parent.Name)].PlayerGui:WaitForChild("TrailShopGUI")
    gui.Enabled = false
    gui.Enabled = true
end)

1 comment

0

It works. Thank you so much!

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