Why is the script not detecting my int value?

So every time a player joins they get assigned a value.
that value stands for how much money they have.
i made a script that detects when it changes and changes the text of a label to the number so a player can see their money value.

when i wanted to add money after doing something it just didn’t detect the int value.
script that checks the int value’s existance:

	local MoneyValue = plr:FindFirstChildWhichIsA("IntValue")
		if MoneyValue.Name == "MoneyValue" then
			MoneyValue.Value = MoneyValue.Value +40
		end

assigner script:

local Player = game.Players.LocalPlayer




local instance = Instance.new("IntValue")
instance.Name = "MoneyValue"
instance.Parent = Player

but it says that it can’t check a nil value’s name.
but it shouldn’t be nil in the first place.
Thanks in Advance!

Which are client scripts and which are server scripts?

Try this code out!!


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

for _, value in pairs(plr:GetChildren()) do
    if value:IsA('IntValue') and value.Name == 'MoneyValue' then
        value.Value += 40
    end
end

The One That Detects the Value is server and the other one is local

edit:changed “script” to “value”

The server script cant find the int value because it is being created from a local script, which is not being replicated to the server

So i have to do it in a server script instead?

So the issue is the server can’t see what the client does. If you assign the value on the client the server see’s nothing.

This should all be handled on the server. You can migrate your client code to the server by utilizing the PlayerAdded event.

game:GetService("Players").PlayedAdded:Connect(function(player)
   local instance = Instance.new("IntValue")
   instance.Name = "MoneyValue"
   instance.Parent = Player
end)

Try making the int value with this server script:

game.Players.PlayerAdded:Connect(function(plr)
    local instance = Instance.new("IntValue")
    instance.Name = "MoneyValue"
    instance.Parent = plr
end)
2 Likes

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