How can I check a BoolValue in a player from a normal script in serverscriptservice

Hello! I am working on a system that will give extra money if the player has a BoolValue that is true. I’m having an issue with consistently checking the Player to see if it is true, yet I’m getting errors. How can I be able to check the local player if their value is true or not?
Code is below
This is from a script in ServerScriptService

game.Players.PlayerAdded:Connect(function(plr)
	local bool = Instance.new("BoolValue",plr)
	bool.Name = "King"
	bool.Value = false
end)

local MoneyBonus = 0

while wait(1) do
	if Player.King.Value == true then
		MoneyBonus = 0.5
	else
		MoneyBonus = 0
	end
end

local bonus = MoneyBonus * Income

Any help on figuring this out is greatly appreciated!

game.Players.PlayerAdded:Connect(function(plr)
    local MoneyBonus = 0
	local bool = Instance.new("BoolValue",plr)
	bool.Name = "King"
	bool.Value = false
    bool:GetPropertyChangedSingal("Value"):Connect(function()
       if bool.Value == true then
          MoneyBonus = 0.5
       else
          MoneyBonus = 0
       end
    end)
end)


Better! The income still isn’t changing though. Im getting the same amount

Have you tried to insert a numberValue into the player and update it instead of the variable?

What errors are you getting ?

No and I’m not getting any errors. Strange.

Are you modifing the value from the server? or from the client?

if modified from the client

bool:GetPropertyChangedSingal("Value"):Connect(function()
       if bool.Value == true then
          MoneyBonus = 0.5
       else
          MoneyBonus = 0
       end
    end)

This would not run.

Its all from the server so no client

Then If the bool value default is false, can i ask you where you put that value to true?

Im working on a King of The Hill System that will make the value true when they become king. Ill be talking about that after I can figure this out

So, Are you sure that when they become the king of the hill the script will change that value? Can you test this?

Yeah the system is able to change the value. I was having issues with making the value false if the king leaves or dies and that only one person can have the value be set to true.

Oh, the code that sent Valk was wrong,
Here’s the fix:

game.Players.PlayerAdded:Connect(function(plr)
	local MoneyBonus = 0
	local bool = Instance.new("BoolValue",plr)
	bool.Name = "King"
	bool.Value = false
	repeat task.wait() until bool.Parent
	bool:GetPropertyChangedSignal("Value"):Connect(function()
		if bool.Value == true then
			MoneyBonus = 0.5
		else
			MoneyBonus = 0
		end
	end)
end)

Simple he was Putting a function before the bool Value is present

3 Likes

And how can I take that and add it to a new function so it gets included in the income? When I put in MoneyBonus in the income I get this error. “ServerScriptService.Main:404: attempt to perform arithmetic (mul) on nil and number”

Nevermind, fixed the issue. Thanks a lot! Hopefully you can help me on my next problem

1 Like