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

My for loop is only running once, how would I make it run more?

COMPLETELY EDITED QUESTION:

I have a model which contains models named 1-13. When one of these models is clicked with a ClickDetector, a GUI will show which contains a close button. However, when the close button is clicked when I click another one of the screens, the GUI will not show. Here is my code:

local register = game.Workspace.Cashier
local frame = script.Parent
	
for i,v in pairs(register:GetChildren()) do		
	v.Screen.ClickDetector.MouseClick:Connect(function(Screen)
		script.Parent.Parent.Enabled = true
	end)
end

1 answer

✓ Accepted answer

So I'm not 100% sure what the "script.Parent.Parent.Enabled" means. If it's in a local script then that is the reason it's not working. Try something like this: - in a server script :)

local register = workspace.Cashier
local event = Instance.new("RemoteEvent")
event.Name = "ClientGui"
event.Parent = game:GetService("ReplicatedStorage")

for _,v in pairs(register:GetChildren()) do
	v.Screen.ClickDetector.MouseClick:Connect(function(player)
		event:FireClient(player)
	end
end

And put this in a local script inside of the gui.

local event = game:GetService("ReplicatedStorage"):WaitForChild("ClientGui")
local gui = script.Parent

event.OnClientEvent:Connect(function()
	gui.Enabled = true
end)

You can also just create the remote event without the script but it should work either way. And by the way, the first argument of MouseClick is the player that clicked it ;)

5 comments

0

The local script is for the GUI and when screen is clicked, I'm going to tween the GUI on the screen. Is this for the new, updated question or the old question as I figured out a solution that I was close tol.

0

um.. this is for this question.

0

Ah alright, I updated the question that's why I asked. I'll try now.

0

And how does the close button make the GUI go away? Does it disable it or does it make it invisible?

0

It tweens it out of the screen and then disables it.

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