How do I write to a StringValue on the client?

Try modifying your code to this:

local plr = game:GetService("Players").LocalPlayer
local team = script.Parent.Parent.SelectedTeam -- only reference the Instance here

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").LoadCharacter:FireServer(team.Value) -- use '.Value' here to get the up-to-date value stored.
    -- if you define team as 'StringValue.Value' it was only store the value that's in place when the game starts
end)

It fixes the “nothing happens” problem, but the value still remains unchanged

i’ve had to sanity check myself twice and make sure I was in fact changing it lmaoa

Is it being changed from the properties window, or from another script?

Hear me out with this new way cause this seems to be causing you a lot of issues.

  1. Set the selected team as an attribute under the player on the client of course (Accesibility)
  2. When a player clicks use getattribute on the local player and send the selected team to the server.

You don’t have to add or change anything from your code and it’s simple too.

1 Like

I’ve never heard of these before… May you elaborate please?

like Player:SetAttribute("Team", "Team1") to set the attribute and Player:GetAttribute("Team") to get the value set. In this case that value would be “Team1”

1 Like

2024-09-20_16-09
same problem as before, whenever the attribute is passed to the server, it returns back to it’s original state

edit: i do like the idea of using attributes more though, very cool

Are you setting the attribute from only one location?

set here

local plr = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	plr:SetAttribute("Team", "Booking")

then passed to the server here

local plr = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").LoadCharacter:FireServer(plr)
end)

then the player gets teamed on the server here

game:GetService("ReplicatedStorage").LoadCharacter.OnServerEvent:Connect(function(plr)
	print(plr:GetAttribute("Team"))
	plr.Team = plr:GetAttribute("Team")
end)

That’s because the attribute is set locally so the server cant see anything.

–Firing

script.Parent.MouseButton1Click:Connect(function()
 game:GetService("ReplicatedStorage").LoadCharacter:FireServer(plr:GetAttribute("Team"))
end)

For the server use the code I gave you before for switching teams because it will now pass a string

oh yea i forgot about that ;;

didn’t seem to change anything tho?

Can you print the attribute on the client before you send it and when you receive it on the server?

i already did that
2024-09-20_16-57
top one is changing it, second one is sending and bottom one is recieving

If the server changes the value it sees, it will replicate to the client. Therefore if you change the value on the client before that happens, the server will overwrite it with its version of the value.

Sorry mb I forgot you sent a screenshot previously. Can you show the updated server code? Is it similar to what I was referencing? Because if the client prints the value showing it exists idk why the server wouldn’t be able to see it (Sorry in advance for the repetition)

1 Like

here it is. idk either

game:GetService("ReplicatedStorage").LoadCharacter.OnServerEvent:Connect(function(plr)
	plr.Team = plr:GetAttribute("Team")
end)

I just said you cant get the attribute from the player :skull:

–Server

game:GetService("ReplicatedStorage").LoadCharacter.OnServerEvent:Connect(function(plr, Team)
	plr.Team = game:GetService("Teams"):FindFirstChild(Team)
end)

–Client

script.Parent.MouseButton1Click:Connect(function()
 game:GetService("ReplicatedStorage").LoadCharacter:FireServer(plr:GetAttribute("Team"))
end)
1 Like

i dont even know exactly what i did, but it’s working now lol

Mark your post as the solution so this forum doesn’t stay live for eternity!

1 Like

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