Unable to set ObjectValue to nil

Hey, I’m having trouble with a build system I’ve been working on. I have a ObjectValue containing the item the player is trying to place but I am unable to set the ObjectValue to nil . I’ve tried multiple ways of doing this but nothing has been of use so far. If someone could direct me to the right solution here that’d be great :+1:

Hi there, could you possibly post a snippet of code where you are trying to do this? Usually setting an ObjectValue to nil should be as simple as objectValue.Value = nil

I tested this in studio and it seemed to work fine, no errors at all.
Make sure you’re setting the .Value and not the ObjectValue itself to nil (I’ve done that a few times).

1 Like

Sure,
local selected_prop = script.Parent.Main.selected_prop.Value
local grid_size = 0.5
local posX
local posY
local posZ

function toggle_building()
	if building then
		building = false
		
		selected_prop = nil
		script.Parent.Main.Visible = false
	elseif not building then
		building = true
		
		selected_prop = nil
		script.Parent.Main.Visible = true
	end
end

note that selected_prop does change

This will get the value not the ValueObject

use

local selected_prop = script.Parent.Main.selected_prop

then

selected_prop.Value = new value
2 Likes

Strange, I’ll have to review my code to make sure the its not getting assigned a new value somewhere