I’m using this turret deployment system free model from thienbao2109 as a basis for my sapper system. From what I understand, when you click, it clones a “turret” (or fortification in my case), parents it to workspace, then puts it in front of you. What I want to know is how I could make it switch what it clones and deploys.
I’ve tried duplicating the scripts with both of them cloning different fortifications, but one is disabled and the other is not. A script that I’ve added also inside of the tool disables one and enables the other, but that doesn’t seem to work. Help? If you need the code, I’ll make an edit
Code:
local canPlace = true
local cooldown = 0.5
function wait(TimeToWait)
if TimeToWait ~= nil then
local TotalTime = 0
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
while TotalTime < TimeToWait do
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
end
else
game:GetService("RunService").Heartbeat:wait()
end
end
script.Build.OnServerEvent:connect(function(player)
local character = player.Character
if canPlace then
canPlace = false
-- Place turret
local fRay = Ray.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -5)))
local hit, position = game.Workspace:FindPartOnRay(fRay, character)
local ray = Ray.new(position, Vector3.new(0, -200, 0))
local hit, pos = game.Workspace:FindPartOnRay(ray, character)
local turret = game.ReplicatedStorage.TestBuild1:Clone()
turret.Creator.Value = player
turret:SetPrimaryPartCFrame(CFrame.new(pos + Vector3.new(0, 0.4, 0)))
turret.Parent = game.Workspace
wait(cooldown)
canPlace = true
end
end)