The client script runs, and it creates a folder, named exactly the player's name. When a car spawns, I am trying to find that folder, and check inside if there is an object, called 'Car'. If there is, then it will destroy it. The problem I am getting, is, that I am unable to find the folder in workspace through the className. Any help? (Both scripts are in ServerScriptService)
game.Players.PlayerAdded:Connect(function(plr)
local cars = Instance.new("Folder")
cars.Name = plr.Name
cars.Parent = workspace
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Dollars"
cash.Value = 122000
cash.Parent = leaderstats
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player, NameOfCar)
return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value
end
end)
--script runs when client starts
local Camaro = game:GetService("ReplicatedStorage"):WaitForChild("Camaro")
Camaro.OnServerEvent:connect(function(player)
local car = game:GetService("ServerStorage").Cars.Camaro
local veh = car:clone()
local folder = workspace:FindFirstChild(player.className("Folder"))
if folder:IsAncestorOf("Car") then
folder.Car:Destroy()
end
veh.PrimaryPart = veh.Main
veh.Parent = folder
veh.Name = "Car"
veh:SetPrimaryPartCFrame(player.Character.Head.CFrame)
end)
--Car spawn script
`

1 comment
The Folder and IntValue instances should be created on the server script.