Ad
Log in to vote
0

Object Value not being set?

Asked by 19 days ago

the Vehicle is an object value and I'm trying to set it to the cloned car, but it does not set. Wondering if I should make the value or script in a different location?

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local VehicleCount = player.leaderstats.vehicle.Value

    if VehicleCount then workspace:FindFirstChild(VehicleCount):Destroy() end
    local car = game.ServerStorage.FordFocus:Clone()
    local prompt = car.VehiclePrompt:WaitForChild("VehicleDriver")
    prompt = player.Name
    car.Parent = workspace
    VehicleCount = workspace:FindFirstChild(car)
end)

1 answer

Log in to vote
1
Answered by 19 days ago

You need to reference the ObjectValue itself, you can’t change the .Value of it when it is set to be a variable.

If you reference the value, then do local value = ObjectValue.Value, it is “stored” inside the variable, and any changes made to that variable (value = workspace) will not change the actual property, but only the variable itself.

(Sorry if this makes no sense, bad at explaining this.)

e.g.

local intValue = workspace.IntValue --set to be 1
local intValueValue = intValue.Value --this variable is currently 1

intValueValue = 2
intValue.Value = 0

print(intValueValue) --2
print(intValue.Value) --0

So your script should look something like this instead:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local VehicleCount = player.leaderstats.vehicle

    if VehicleCount.Value then
        workspace:FindFirstChild(VehicleCount.Value):Destroy()
    end

    local car = game.ServerStorage.FordFocus:Clone()
    local prompt = car.VehiclePrompt:WaitForChild("VehicleDriver")
    prompt = player.Name
    car.Parent = workspace
    VehicleCount.Value = workspace:FindFirstChild(car)
end)
0
Hi! Thank you so much for answering! It writes to the object value, but now SamZeKat 28 — 19d
0
Oops- forgot to finish writing the comment but i fixed it haha SamZeKat 28 — 19d
Ad

Answer this question