I want to do a smart clone of the model (my boat). Here’s how my cloning works I go to the NPC and I get a window with the choice of spawn boats.
I have the code,but it doesn’t work the way I need. I have a script that looks for a model in the region, and if there is no model, when I click on the button, my model (boat) will spawn, but there is an error, because even when there is a boat, it still clones it, although as I said, I made a script that looks for a model, and only when it does not find it will spawn. Does anyone know what the problem is?
I tried to create a variable that determines when the boat is in the region, but it doesn’t help, or I did something wrong.
My script are server.
local ServerStorage = game:GetService("ServerStorage")
local Boat1 = ServerStorage:FindFirstChild("Boat1")
local Button = script.Parent
local Main = Button.Parent
local WhiteRegionCheck = game.Workspace:WaitForChild("WhiteRegionCheck")
local Position1 = WhiteRegionCheck.Position - (WhiteRegionCheck.Size / 2)
local Position2 = WhiteRegionCheck.Position + (WhiteRegionCheck.Size / 2)
local Region = Region3.new(Position1, Position2)
Button.MouseButton1Down:Connect(function(Click)
local PartsInRegion = workspace:FindPartsInRegion3(Region, nil, 1000)
for i, Parts in pairs(PartsInRegion) do
wait(1)
if not Parts.Parent:FindFirstChild("Boat1") then
local CloneBoat1 = Boat1:Clone()
print("Cloned")
CloneBoat1.Parent = game.Workspace
Main.Visible = false
break
end
end
end)