String value not updating in server

hello, ive been trying to get the string value to update in the server but it doesnt change the value, ive already printed to see if it would print the players name and it did, this is a server script and i have no idea what to do. can someone pls help me!!!

QueuePad.Touched:Connect(function(hit)
	local Player = hit.Parent
	local Humanoid = Player:FindFirstChildOfClass("Humanoid")
	if Deb == true then
		if Humanoid then
			if StringP1 == nil or game.Players:FindFirstChild(StringP1) == nil then
				Deb = false
				StringP1 = Player.Name
				print(StringP1.. " is the first player.")
				task.wait(2)
				Deb = true
			elseif StringP2 == nil or game.Players:FindFirstChild(StringP2) == nil then
				Deb = false
				StringP2 = Player.Name
				print(StringP2.. " is the second player.")
				task.wait(2)
				Deb = true
			elseif StringP3 == nil or game.Players:FindFirstChild(StringP3) == nil then
				Deb = false
				StringP3 = Player.Name
				print(StringP3.. " is the third player.")
				task.wait(2)
				Deb = true
			elseif StringP4 == nil or game.Players:FindFirstChild(StringP4) == nil then
				Deb = false
				StringP4 = Player.Name
				print(StringP4.. " is the fourth player.")
				task.wait(2)
				Deb = true
			else
				print("Queue is full.")
			end
		end
	end
end)

1 Like

You’re setting the StringValue object to Player.Name.
Shouldn’t you be setting the object’s value to the player instead? StringValue.Value?

1 Like

no, the variable i didnt provide outside the script already has .value at the end

fyi,

local Rep = game:GetService("ReplicatedStorage")
local StringP1 = Rep.Players.Player1.Value
local StringP2 = Rep.Players.Player2.Value
local StringP3 = Rep.Players.Player3.Value
local StringP4 = Rep.Players.Player4.Value
local QueuePad = game.Workspace:WaitForChild("QueueThing")
local Deb = true

But then wouldn’t you just be setting StringP1 to the value? That only happens once:
Reps.Players.Player1.Value → “Initial Value”
StringP1 → “Initial Value”

2 Likes

You can’t just do that. You aren’t setting the StringValue value

1 Like

have you tried StringP1 == “” instead?

sooo ur issue is that u did this at the top:

local StringP1 = Rep.Players.Player1.Value

see when u do .Value there, ur basically just copying the value itself (like an empty string or whatever) into the variable. its NOT referencing the actual StringValue object anymore, its just like..a copy of whats inside it u know?

so later when u do StringP1 = Player.Name, ur just changing that local variable copy. the actual StringValue object in ReplicatedStorage is like “lol i didnt change bro” cuz ur not actually working with it

local Rep = game:GetService("ReplicatedStorage")
local StringP1 = Rep.Players.Player1  -- no .Value here!!
local StringP2 = Rep.Players.Player2  -- no .Value here!!
local StringP3 = Rep.Players.Player3  -- no .Value here!!
local StringP4 = Rep.Players.Player4  -- no .Value here!!
local QueuePad = game.Workspace:WaitForChild("QueueThing")
local Deb = true

then in ur touched function, change it to:

StringP1.Value = Player.Name  -- NOW use .Value to update it
1 Like

ah i see, thank you very much that fixed it! your logic here makes perfect sense, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.