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

Why isn't this GUI giver working properly with more than 1 player in the server?

Asked by 8 years ago
Edited 8 years ago

Hello there. This system is meant to be that when you step on it, it gives you a GUI that counts down and when it reaches 0, it gives you the money then deletes it self. This works while playing alone, however... when there's another player in the server, it gets stuck at 14 on the countdown, until the other player steps on the pad as well. Then it continues to countdown, until it reaches 1. It gives the money but doesn't delete the GUI, like it does solo.

Layout: http://prntscr.com/bvajfp

Main Script:

01time = 15
02 
03while true do
04    wait(1)
05    time = time - 1
06    if (time == 0) then
07        time = 15
08        players = game.Players:GetChildren()
09        for i=1, #players do
10            if (players[i]:findFirstChild("leaderstats")) then
11                    players[i].leaderstats.Money.Value = players[i].leaderstats.Money.Value + 30000
12                    script.Parent:Destroy()
13                end
14            end
15        end
View all 21 lines...

GUI Giver script, located in head:

01local debounce = false
02function getPlayer(humanoid)
03local players = game.Players:children()
04for i = 1, #players do
05if players[i].Character.Humanoid == humanoid then return players[i] end
06end
07return nil
08end
09 
10function onTouch(part)
11 
12local human = part.Parent:findFirstChild("Humanoid")
13if (human ~= nil) and debounce == false then
14 
15debounce = true
View all 29 lines...

1 answer

Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

I'm not entirely sure what this is supposed to do, but to fix your problem, you should replace line 19 with this:

1if playersa[i].PlayerGui:FindFirstChild("FlashGUI") then
2    playersa[i].PlayerGui.FlashGUI.text.Text = "You will recieve the money in: " .. tostring(time)
3end

Also, a bit of advice for looping through players: instead of doing:

1local Players = game.Players:GetChildren()
2for i = 1, #Players do
3    -- Do stuff
4    Players[i].X = Y
5end

You can (and should) use generic for loops, which look like this:

1for i, v in ipairs(game.Players:GetChildren()) do
2    v.X = Y
3end

This should be at least one problem solved. I'm still not sure this works entirely as you intended.

Edit: Disable the main script, then add this after line 21 of the giver script:

1player.PlayerGui.FlashGUI.Script.Disabled = false
0
Is this the proper change? http://prntscr.com/bvorsd If so, it doesn't work and gives this error message: http://prntscr.com/bvos7d alexduskthorn 40 — 8y
0
Change the players[i] to playersa[i] IDidMakeThat 1135 — 8y
0
Changed, its now doing this. https://gyazo.com/ffe999cfa77bf5067b051cfb0e8c5867 alexduskthorn 40 — 8y
0
I have edited the answer to fix that. IDidMakeThat 1135 — 8y
Ad

Answer this question