Hi!
I’m trying to make a script that clones a tool (basically like throwing the object.). The problem is that it clones my tool 2 times instead of one time.
I don’t really see a problem with my script, because I added a debounce and all.
Anyways, here’s my script:
local touched = false
local TS = game:GetService("TweenService")
local clicked = false
game.ReplicatedStorage.Throw.OnServerEvent:Connect(function(plr, mouseHit)
if not clicked then
clicked = true
local clone = plr.Character:FindFirstChildWhichIsA("Tool").Handle:Clone()
plr.Character.Humanoid:LoadAnimation(script.Parent.Handle:FindFirstChild("Yeet")):Play()
clone.Hitbox.Touched:Connect(function(hit)
if not touched then
touched = true
clone.CanTouch = false
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= plr.Character and hit.Parent.Name ~= "Rope" and hit.Parent.Name ~= "Celestial Worm" then
--print(hit.Parent)
if hit.Parent.Humanoid.Health > 0 then
local target = hit.Parent
local joints = target:GetDescendants()
target.Humanoid.BreakJointsOnDeath = false
game.ReplicatedStorage.YeetGain:FireClient(plr)
local killed = false
target.Humanoid.Died:Connect(function(killed)
game.ReplicatedStorage.YeetGainDeath:FireClient(plr)
end)
print(target.HumanoidRootPart)
target.HumanoidRootPart.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 160 + Vector3.new(0,160,0)
print(target.HumanoidRootPart)
clone.Impact:Play()
print(hit.Parent.Name.." was hit by "..script.Parent.Name)
--if not extraTouch then
-- extraTouch = true
target:FindFirstChild("Humanoid").Health -= 10
--wait(1)
--extraTouch = false
--end
for _,joint in pairs(joints) do
if joint:isA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
print(joint)
target.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
target.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
target.Humanoid.AutoRotate = false
--target.Humanoid.PlatformStand = true
--target.Humanoid.WalkSpeed = 0
--target.Humanoid.JumpPower = 0
att0.Name = "Att0"
att1.Name = "Att1"
att0.CFrame = joint.C0
att1.CFrame = joint.C1
att0.Parent = joint.Part0
att1.Parent = joint.Part1
touched = true
clone.CanTouch = false
socket.Parent = joint.Part0
socket.Attachment0 = att0
socket.Attachment1 = att1
att0.Name = "Att0"
att1.Name = "Att1"
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
--wait(0.2)
--wait(2)
joint.Enabled = false
end
end
print(target)
print(target.Humanoid.Health)
wait(0.2)
clone:Destroy()
wait(0.1)
touched = false
clone.CanTouch = true
wait(0.9)
if hit.Parent.Humanoid.Health > 0 then
if target.Name ~= "Dummy3" then
target.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
target.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
target.Humanoid.AutoRotate = true
target.Humanoid.WalkSpeed = 26
target.Humanoid.JumpPower = 7.5
for _,joint2nd in pairs(joints) do
if joint2nd:isA("Motor6D") then
joint2nd.Enabled = true
end
end
for _, child in pairs(target:GetDescendants()) do
if child.Name == "Att0" or child.Name == "Att1" or child:IsA("BallSocketConstraint") then
child:Destroy()
end
end
end
end
end
end
end
end)
wait(0.4)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Woosh:Play()
wait(0.1)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Transparency = 1
clone.Transparency = 0
local tool = clone.Parent
clone.Parent = game.Workspace
clone.Anchored = true
clone.CanCollide = false
clone.Hitbox.CanCollide = false
clone.CanTouch = true
clone.Hitbox.CanTouch = true
print(clone.Parent)
-- clone.Position = script.Parent.Handle.Position
clone.CFrame = plr.Character.HumanoidRootPart.CFrame+plr.Character.HumanoidRootPart.CFrame.LookVector * 5
local Tween = TS:Create(clone,TweenInfo.new(0.5),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 80})
Tween:Play()
--print(mouseHit)
wait(0.45)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Transparency = 0
clone:Destroy()
clicked = false
end
end)
--clone.Touched:Connect(function(hit)
--local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
--print(plr,"was hit by",script.Parent.Name)
--end)
Any of your help is appreciated!