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

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

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:

time = 15

while true do
	wait(1)
	time = time - 1
	if (time == 0) then
		time = 15
		players = game.Players:GetChildren()
		for i=1, #players do
			if (players[i]:findFirstChild("leaderstats")) then
					players[i].leaderstats.Money.Value = players[i].leaderstats.Money.Value + 30000
					script.Parent:Destroy()
				end
			end
		end
	
	playersa = game.Players:GetChildren()
	for i=1, #playersa do
		playersa[i].PlayerGui.FlashGUI.text.Text = "You will recieve the money in: " .. tostring(time)
	end
end

GUI Giver script, located in head:

local debounce = false
function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent.Parent:findFirstChild("FlashGUI"):clone().Parent = player.PlayerGui

wait(5)
debounce = false
end
end


script.Parent.Touched:connect(onTouch) 

1 answer

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

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

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

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

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

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

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:

player.PlayerGui.FlashGUI.Script.Disabled = false

4 comments

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

0

Change the players[i] to playersa[i]

0
0

I have edited the answer to fix that.

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