I actually understood that you want a button to change for all players when a single player clicks it.
Now you are saying that you don’t know how to change the values when running a for loop without running multiple times?
Do you mean the same value or player passing through the loop again or do you mean running a complete for loop once because it runs multiple times in your code?
- Here are some comments on your code
local Players = game:GetService("Players")
local plrs = {} --Why do you want to make another player array when you already get one by :GetPlayers()?
table.insert(Players:GetPlayers(), plrs) --Table insert doesn't work like that, table.insert ( array t, number pos = #t+1, Variant value )
local door = workspace.StartingArea:WaitForChild("Door")
local remote = game.ReplicatedStorage.Remotes.Start
function Start()
local counter
local button
for i = 1, #plrs do --You can't use a for-loop because your array is nill (wrong usage of table.insert) also using :GetPlayers() returns 0 in for-loops
local UI = plrs[i]:WaitForChild("PlayerGui") -- 0
counter = UI.Start.Counter
button = UI.Start.Button
end
for i = 5, 0, -1 do
print(i)
counter.Text = i
if i == 0 then --You can just replace this statement at the end of the for loop because the for loop will stop at 0.
counter.Text = "GO!"
counter:TweenSize(UDim2.new(1, 0, 1, 0), "Out", "Quart", .2)
wait(.5)
counter:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Quart", .2)
wait(.5)
else
counter:TweenSize(UDim2.new(1, 0, 1, 0), "Out", "Quart", .2)
wait(.2)
counter:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Quart", .2)
wait(.8)
end
end
door:Destroy()
end
remote:InvokeServer(script.Parent.Button.MouseButton1Click:Connect(Start)) -- Not the correct way to InvokeServer!
Please make sure to check these out
- Here is a working edit of your code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Event")
local function Start()
local Players = game:GetService("Players")
local GetPlrs = Players:GetChildren()
for i, Plr in ipairs(GetPlrs) do --]] Loops players
print(Plr.Name)
local PlrUI = GetPlrs[i]:WaitForChild("PlayerGui")
-- local StartUI = PlrUI.UI.Start.Counter
-- local ButtonUI = PlrUI.UI.Start.Button
-- Rest of code..
end
for i = 5, 0, -1 do --]] Countdown
-- Counter.Text = i
-- Counter:TweenSize(UDim2.new(1, 0, 1, 0), "Out", "Quart", .2)
-- wait(.2)
-- Counter:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Quart", .2)
-- wait(.8)
print("Counter: "..i)
end
-- Counter.Text = "GO!"
-- counter:TweenSize(UDim2.new(1, 0, 1, 0), "Out", "Quart", .2)
-- wait(.5)
-- Counter:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Quart", .2)
-- wait(.5)
print("Counter: GO!")
wait(.1)
-- door:Destroy()
print("Removed Door")
end
-- Assuming the RemoteFunction is Client-Server
Event.OnServerInvoke = Start
By the way did the previous reply answer your question?
Also if this doesn’t answer your question may be consider messaging me.