Simple print script won't work for finding values


So I added a folder and values to a player and the name of the value is ‘human’.

image
But when I ran a script to see if it would detect the values nothing would print in the output

I haven’t been scripting in a long time and forgot most things. I am using a local script to find the local player and the values in it. Any help would be appreciated.

local Players = game:GetService("Players")
local Race = Players.LocalPlayer.PlayerValues.Race.Value

if Race == "Human" then
	
	print ("Yes")
end

maybe add

local Players = game:GetService("Players")
local Race = Players.LocalPlayer.PlayerValues.Race.Value
game.Players.PlayerAdded:Connect(function()
if Race == "Human" then
	
	print ("Yes")
end
end)

Yeah, maybe don’t do that? Do this instead, you can’t save the values as a variable.

local Players = game:GetService("Players")
local Race = Players.LocalPlayer.PlayerValues.Race

if Race.Value == "Human" then
	
	print ("Yes")
end
2 Likes

Nothing seems to be printing for some reason. There is no errors or anything just
image

Hmm, sorry but i don’t know the solution, thought it would work. Anyways, try your best to find the issue and make it work.

Maybe try a different type of script. For example if its a LocalScript try a Server Script

image

Yeah this is the result it gave me. I don’t think server scripts can work into local player

1 Like

Just realized, since it’s in the localscript it fires maybe faster? You should add a wait() and maybe it’ll fix it?

Edit: btw the normal scripts don’t work if it has a player variable involved it via services

That’s because local player doesn’t exist on a server script. That variable is only for local scripts on the client.

Put this in a local script in StarterPlayerScripts. Often if something isn’t working on the client it’s because of replication. Waiting for things to be replicated fixes this.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerValues = Player:WaitForChild(“PlayerValues”)
local Race = PlayerValues:WaitForChild(“Race”)

if Race.Value == "Human" then
	print ("Yes")
else -- this is just to check the code is running and everything
	print(Race.Value)
end

- PseudoPerson
Written on mobile

1 Like