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

How to reference a player with a StringValue?

Hello there, I have a very complicated situation here, what I want to happen is that if the player presses the TextButton, the GUI in that player's TextButton gets disabled while that GUI is enabled for another player, not all players (Think of it like the 6 passing something repeatedly)

The only solution I could think about this is referencing the players as StringValue then just detect if Player1 has pressed the TextButton, the TextButton is disabled, pass it to Player2 by checking if Player2's value has the same value as the player's name, I'm really confused about this and do not know how to approach this, how does one remedy this?

(Also thanks for ZeroToH3ro for helping me solve my recent problem with my StringValues)

local playervalues = game.Workspace.PlayerStrings
local gui = game.StarterGui.Roll
local RS = game:GetService("ReplicatedStorage")
local PassEvent = RS:WaitForChild("PassEvent")


value1 = playervalues:WaitForChild("Player1")
value2 = playervalues:WaitForChild("Player2")
value3 = playervalues:WaitForChild("Player3")
value4 = playervalues:WaitForChild("Player4")
value5 = playervalues:WaitForChild("Player5")
value6 = playervalues:WaitForChild("Player6")

--PSEUDOCODE

--if player1 presses button, game detect and find if player1's string value is the same as target player's name, disables gui for player1, game detect and find if player2's string value is the same as target player's name, if true then enable gui for player2, if player2 presses button, game detect and find if player2's string value is the same as target player's name ,fi true then disable gui for player2, game detect and find if player3's string value is the same as target player's name, if true then enable gui for player3--

	
end



1 answer

✓ Accepted answer

i dont 100% understand but i made a general outline for u, this should work


local playervalues = game.Workspace.PlayerStrings
local gui = game.StarterGui.Roll
local RS = game:GetService("ReplicatedStorage")
local PassEvent = RS:WaitForChild("PassEvent")

local plrs = game:GetService("Players"):GetPlayers()
local targetPlayer = plrs[Random.new():NextInteger(1,#plrs)] --getting a random player & making them the targetPlayer

gui.MouseButton1Click:Connect(function()
	for i,plr in pairs(plrs) do
		if plr.Name == targetPlayer.Name then --if player's name is target player's name
			--do stuff
		else
			--do stuff
		end
		
	end
end)

2 comments

1

This worked but it's a little scuffed, but don't worry I'll revise it thanks for your help again

0

np, good luck brother!

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