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

[SOLVED] Why Is My GUI Giver is Giving Everyone The GUI When 2 People Should be Getting The GUI?

I was setting the variable value, not the actual value. This is considered solved

local player1 = game.ReplicatedStorage.ServerRoundStats.Player1.Value
local player2 = game.ReplicatedStorage.ServerRoundStats.Player2.Value
local playercount = 0
local csc = game.ReplicatedStorage.Remotes.CStartRoundC
local cs = game.ReplicatedStorage.Remotes.CStartRound
local afked = game.ReplicatedStorage.Remotes.AFKPlayer
game.ReplicatedStorage.Remotes.StartRound.Event:Connect(function()
	for i,v in pairs(game.Players:GetChildren()) do
		playercount = playercount + 1
	end
	repeat
	for i,v in pairs(game.Players:GetChildren()) do
		if player1 == nil then
			local random = math.random(1,playercount)
			if random == 1 then
				player1 = v.Name
				v.Role.Value = "P1"
			end
		else
			if player2 == nil then
				local random2 = math.random(1,playercount)
				if random2 == 1 then
					player2 = v.Name
					v.Role.Value = "P2"
				end
			end
		end
	end
until player1 ~= nil and player2 ~= nil
for i,v in pairs(game.Players:GetChildren()) do
	if v.Role.Value == nil then
		cs:FireClient(v)
	else
	csc:FireClient(v)
	end
end
end)

afked.OnServerEvent:Connect(function(plr)
	if player1 == plr.Name then
		player1 = nil
		for i,v in pairs(game.Players:GetChildren()) do
		local random = math.random(1,playercount - 1)
			if random == 1 then
			if v.Name ~= plr.Name then	
			player1 = v.Name
		v.Role.Value = "P1"
		else 
		repeat
		for i,v in pairs(game.Players:GetChildren()) do
		local random = math.random(1,playercount - 1)
			if random == 1 then
			if v.Name ~= plr.Name then	
			player1 = v.Name
		v.Role.Value = "P1"
		end
		end
		end
		until player1 ~= nil and player1 ~= plr.Name
		end
		end
	end
	else
		if player2 == plr.Name then
					player2 = nil
		for i,v in pairs(game.Players:GetChildren()) do
		local random = math.random(1,playercount - 1)
			if random == 1 then
			if v.Name ~= plr.Name then	
			player2 = v.Name
		v.Role.Value = "P2"
		else repeat
		for i,v in pairs(game.Players:GetChildren()) do
		local random = math.random(1,playercount - 1)
			if random == 1 then
			if v.Name ~= plr.Name then	
			player2 = v.Name
		v.Role.Value = "P2"
		end
		end
		end
		until player2 ~= nil and player2 ~= plr.Name
		end
		end
		end
		else
	 return
end 	
	end
end)

The LocalScript (Should only give the 2 people from the last script the GUI)

local reg = game.ReplicatedStorage.Remotes.CStartRound
local chose = game.ReplicatedStorage.Remotes.CStartRoundC
local sendreq = game.ReplicatedStorage.Remotes.WaitForCode
local plr = game.Players.LocalPlayer
local remotevote = game.ReplicatedStorage.Remotes.StartVoteTimer
local player1 = game.ReplicatedStorage.ServerRoundStats.Player1.Value
local player2 = game.ReplicatedStorage.ServerRoundStats.Player2.Value

reg.OnClientEvent:Connect(function()
--nothing needs to be done--
end)

chose.OnClientEvent:Connect(function()
	if plr.Name == player1 or player2 then
	local gui = game.ReplicatedStorage.Guis.AudioCode:Clone()
	gui.Parent = plr.PlayerGui
	sendreq:Fire()
end
	
end)

remotevote.Event:Connect(function()
	local gui = game.ReplicatedStorage.Guis.VotingGUI
	gui.Parent = plr.PlayerGui
end)

3 answers

✓ Accepted answer

Answer was I wasn't setting the value, I was setting the variable.

Sometimes it can be buggy to say, "player1 or player2," so just try saying,

if plr.Name == player1 or plr.Name == player2 then

Hope this helped! :)

Maybe you forgot to put it in Local Script so that only clients can see it.

1 comment

0

I said I put it in a local script. Thank you for trying to help though!

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