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.
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.
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.
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)