ObjectValue not assigning it's value to a Player Object

So, as the title says an ObjectValue refuses to change it’s value if it’s a Player, I’m not sure if the ObjectValue refuses to change at all, but I’m trying to use it to store a Player Value and it’s not working. Here’s how I do it.

function changevalue(Player)
    local bools = Player.Bools
    local value = Bools.BombPlanted
    value.Value = Player
end

local bools = Instance.new("Folder",Player)
bools.Name = "Bools"

local bombplanted = Instance.new("ObjectValue", bools)
bombplanted.Name = "BombPlanted"
bombplanted.Value = nil

Remote.OnServerEvent:Connect(function(Player)
    changeValue(Player)
end

To clarify, when calling the object value’s value after “changing it” it returns nil, just like when it was Instanced.

Are you attempting to set the value of a Value to Player ? I don’t know if that’s possible. What exactly are you attempting to do here?

Yes, I am trying to set the value of an ObjectValue to a player. I’m pretty sure it should work since, it’s an object. Don’t know if I’m wrong.

function changevalue(Player)
    local bools = Player.Bools
    local value = Bools.BombPlanted -- Are you indexing the correct bools variable?
    value.Value = Player
end

It seems as if your getting the bools variables mixed up? You define “bools” then index “Bools” with an uppercase? It’s also a bad idea to have “bools” declared outside a function and also declaring the same variable in a function scope.

Try changing the “bools” variable inside of changevalue() to “playerbools” instead. That way, you can reference the original variable and the function variable.

1 Like

It does not matter, the function works correctly when I debbuged it, this is just sample code showing how the error is happening. If there is even an “Error” since the output shows nothing about the ObjectValue, but when I debbuged it to try and see if it was the function. It wasnt.

Ok, just remember that case sensitivity does matter. It could of been an issue if that was the usage. It’s a valid line if Bools does exist.

It’s also bad practice to have a variable accessible by any function, but declaring the same variable inside a function scope.

In this case, It doesn’t “bools” when the object value is created is just Player.Bools, I just didnt capitalize the b when localizing it

“bools” variable is created after the ObjectValue instance is created due to the fact that that is an event function.

1 Like

You’re trying to use bools outside of the scope of the changevalue function.

Is the function supposed to add a value object to the player or is ‘Bools’ already created in the player somewhere else?

It isn’t. Instance, bools means Instance, parent. Bools was created before creating the Object value

Yes, it is created right before the Object Value is created. I’ll put it there to avoid confusions.

Is the Event firing? Could you maybe give us an overview of the client firing script?

Could be you setting the player from the event and it’s constantly changing it, OR you didn’t account for delay.

function plantBomb()
	BombPlant:FireServer()			
	print("bruh")
end

UIS.InputBegan:Connect(function(input,IsTyping)
	if IsTyping then
	  return
      elseif input.KeyCode == Enum.KeyCode.T then
        plantBomb()
    end
end)

this is ran through a local script, and yes it does print bruh when you press T

function changevalue(player)
    local pbools = player.Bools
    local value = pbools.BombPlanted
    value.Value = player
end

local bools = Instance.new("Folder", Player)
bools.Name = "Bools"

local bombplanted = Instance.new("ObjectValue", bools)
bombplanted.Name = "BombPlanted"
bombplanted.Value = nil

Remote.OnServerEvent:Connect(function(player) -- Changed to lower case
    changeValue(player)
end

You need to fix your variables. Computers can be confused between two variable which leads to unexpected results. In your example (Being applied or not), has a Player variable used as a local variable and a function paramater. Same for the bools variable.

Be certain that nothing else is trying to set the variable, also, make sure the parameters being passed in are in fact not nil. If it’s not the variable naming, then it’s most likely a part of your code we cannot see.

You don’t have a debounce on that, Disconnect the object like so

function plantBomb()
	BombPlant:FireServer()			
	print("bruh")
end

local DisconnectMe; DisconnectMe = UIS.InputBegan:Connect(function(input, GameInput)
	if Input.KeyCode == Enum.KeyCode.T and not GameInput then
        plantBomb()
        DisconnectMe:Disconnect()
    end
end)

Reconnect when ready

I do have a debounce on that, It’s sample code and I simplified it to not copy and paste a mess here.

what is the thing that isnt working

local bools = Player.Bools
local value = Bools.BombPlanted

Found that you capitalized “Bools” in the second variable. Did you mean to call the first variable, or not?

The ObjectValue is not being assigned the player who fired the event.