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

Why wont my start button work, and count for all players?

Asked by 4 years ago
script.Parent.MouseButton1Click:Connect(function()
    for i,Player in pairs(game.Players:GetPlayers()) do
        local count = Player.PlayerGui.Start.count
        local Parent = Player.PlayerGui.Start.Start
        count.Visible = true

        Parent.Visible = false
        count.Text = 5
            wait(1)
        count.Text = 4
            wait(1)
        count.Text = 3
            wait(1)
        count.Text = 2
            wait(1)
        count.Text = 1
            wait(1)
        count.Text = "BEGIN!"
    end
    game.Workspace["start part"]:Destroy()
    wait(1)
    game.StarterGui["Start"]:Destroy()
    script.Parent.Parent:Destroy()
end

It's supposed to do that on everyone's screen, but it doesn't. The original worked, but only on the "player who clicked it"'s screen. Why?

2 answers

Log in to vote
0
Answered by
DrShockz 233 Moderation Voter
4 years ago

Please ensure the this isn't in a "localscript" if it is, it will only run for the player who executed the script.

0
this won't work bcuz of FilteringEnabled. ServerScripts can't see any descendants of PlayerGui Luka_Gaming07 534 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Problem

The Problem here is that you are using A LocalScript and trying to change something on other Clients (AKA Players). Because of FilteringEnabled this simply won't work.

Solution

RemoteEvents is your Answer. For a guide of using RemoteEvents click Here. Basically what you want to do is

LocalScript

  1. Create a RemoteEvent in ReplicatedStorage
  2. Connect a function to Listen for MouseButton1Click.
    • Which fires the RemoteEvent using RemoteEvent:FireServer()
  3. When RemoteEvent.OnClientEvent is fired do the CountDown

Normal Script

  1. Connect to the Event RemoteEvent.OnServerEvent
    1. Which fires the Event using RemoteEvent:FireAllClients()
    2. And Destroys start part

Final Script

LocalScript

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.<REMOTE EVENT HERE>:FireServer()
end)

game.ReplicatedStorage.<REMOTE EVENT HERE>.OnClientEvent:Connect(function()
    count.Visible = true

        Parent.Visible = false
        count.Text = 5
            wait(1)
        count.Text = 4
            wait(1)
        count.Text = 3
            wait(1)
        count.Text = 2
            wait(1)
        count.Text = 1
            wait(1)
        count.Text = "BEGIN!"

        wait(1)
    script.Parent.Parent:Destroy()
end)

Server Script

game.ReplicatedStorage.<REMOTE EVENT HERE>.OnServerEvent:Connect(function()
    game.ReplicatedStorage.<REMOTE EVENT HERE>.FireAllClients()
    game.Workspace["start part"]:Destroy()
end)
0
Didn't work, despite it looking like it would. Trisodin529 89 — 4y
0
Didn't work, despite it looking like it would. Trisodin529 89 — 4y

Answer this question