Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script keepthinking"SelectedCar"is a intvalue,but the previous selctedcar got deleted?

Asked by 5 years ago

i made a car spawner that spawns a car. but the script keeps thinking it is an intvalue, even tho the previous selectedcar which was an intvalue got deleted.

spawner script:

game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player)
    for i,v in pairs(player.Character:GetChildren()) do
        if v:IsA("Model") then
            v:Destroy()
        end
    end
    wait(1)
local c = player:WaitForChild("SelectedCar"):Clone()
c:SetPrimaryPartCFrame(player.Character.Torso.CFrame)
c.Parent = player.Character
c:MakeJoints()
end)

script that clones car to player:

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
    for _,v in pairs(plr.Cars.Car1:GetChildren()) do
            if plr.SelectedCar then
                plr:WaitForChild("SelectedCar"):Destroy()
                        local e = v:Clone()
                        e.Name = "SelectedCar"
        e.Parent = plr
            else
                                            local e = v:Clone()
        e.Parent = plr
        e.Name = "SelectedCar"
                end
        end
end)

LB script:

game.Players.PlayerAdded:Connect(function(player)
    wait()
    local d = Instance.new("IntValue")
    d.Name = "Cars"
    d.Parent = player
    local car1 = Instance.new("IntValue")
    car1.Name = "Car1"
    car1.Parent = d
    local car2 = Instance.new("IntValue")
    car2.Name = "Car2"
    car2.Parent = d
    local f = Instance.new("IntValue")
    f.Name = "SelectedCar"
    f.Parent = player
    local da = Instance.new("Folder")
    da.Name = "Carbin"
    da.Parent = player

end)

thx

0
indent your code properly aaaaaaaa User#19524 175 — 5y

Answer this question