How to change values on specific players?

I need that when you click on the button in the GUI, the value will change only for the player who clicked the button, how do I do this?

Every time I attempt to change or check a player value, I get an error that script can’t find the value

here’s my script:

Players.PlayerAdded:Connect(function(player)
	local Value = Instance.new("BoolValue")
	Value.Parent = player
	AfkEvent:FireClient(player)
end)

AfkEvent.OnServerEvent:Connect(function(plr)
	if plr:WaitForChild("Value") == true then
		plr.PlayerGui.Value = false
	end
end)

If I understood your code, I think that I found an issue: you parent the Value, that has been created inside of PlayerAdded event, to the player and try to access it by saying player.PlayerGui.Value; It should be more like player.Value = false, because the value is located inside of the player and not inside of its PlayerGui

script still doesn’t see the value

Since this is the server version, can you send me the client one?

I would suggest assigning a name to the Value you created: Value.Name = “AFKStatus”

I already tried to name the value, but it didn’t work.

here’s my scripts

Server:

Players.PlayerAdded:Connect(function(player)
	local Value = Instance.new("BoolValue")
	Value.Parent = player.PlayerGui
	AfkEvent:FireClient(player)
end)

TAfkEvent.OnServerEvent:Connect(function(plr)
	if plr.Value == true then
		TAfkEvent:FireClient(true)
	end
end)

Local:

AfkEvent.OnClientEvent:Connect(function()
	task.wait(10)
	TAfkEvent:FireServer()
	TAfkEvent.OnClientEvent:Connect(function(bool)
		if bool == true then
			AfkDetected()
			scream.Playing = true
		end
	end)
end)

So, I don’t really understand what you meant to do there (I’m sorry for saying this but the client side script is too messy), however, I did this:

local PS = game:GetService("Players")
local AfkEvent = game:GetService("ReplicatedStorage").AfkEvent

--Server
PS.PlayerAdded:Connect(function(plr)
	local AFKStatus = Instance.new("BoolValue")
	AFKStatus.Name = "AfkStatus"
	AFKStatus.Parent = plr
	
	AFKStatus.Changed:Connect(function(afkStatus)
		if afkStatus == true then
			AfkEvent:FireClient(plr)
			print("plr is afk")
		else
			print("plr is not afk")
		end
	end)
end)

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

local AfkEvent = game:GetService("ReplicatedStorage").AfkEvent

local function onAfk()
	print("plr is afk")
end

AfkEvent.OnClientEvent:Connect(function()
	onAfk()
end)

It’s not exactly what I need, but because of your script, I figured out what’s wrong, thank you!

1 Like

No problem. Good luck scripting!

1 Like

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