okay so.
this script is in a part with ClickDetector (I didn’t wrote that sorry):
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
script.Parent.MouseClick:Connect(function(hit)
local backpack = player:WaitForChild("Backpack")
local cloneTool = game:GetService("ServerStorage")["Tactical Knife"]:Clone()
cloneTool.Parent = backpack
end)
end)
end)
and the script is in ServerScriptService is a Hitbox script that welds a part to player to damage the other player that touches the part.
This is the script:
local rs = game:GetService("ReplicatedStorage")
local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")
function newHitbox(character, size, offset, damage, linger)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
local weld = Instance.new("WeldConstraint", hrp)
local hitbox = Instance.new("Part")
weld.Part0 = hrp
weld.Part1 = hitbox
hitbox.Transparency = 1
hitbox.CanCollide = false
hitbox.CanQuery = false
hitbox.Massless = true
hitbox.Size = size
hitbox.CFrame = hrp.CFrame + hrp.CFrame.LookVector * offset.X + Vector3.new(0,offset.Y)
hitbox.Parent = character
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") == nil then return end
for _, v in pairs(hitbox:GetChildren()) do
if v:IsA("ObjectValue") then
if v.Value == hit.Parent then return end
end
end
local hitCounter = Instance.new("ObjectValue", hitbox)
hitCounter.Value = hit.Parent
hit.Parent.Humanoid:TakeDamage(damage)
end)
game.Debris:AddItem(hitbox, linger)
end
hitboxEvent.OnServerEvent:Connect(function(plr, size, offset, damage, linger)
newHitbox(plr.Character, size, offset, damage, linger)
end)
and the LocalScript is in the tool:
local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local events = rs:WaitForChild("Events")
local hitboxEvent = events:WaitForChild("Hitbox")
local plr = game.Players.LocalPlayer
plr.CharacterAdded:Connect(function(char)w
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local currentPunch = 0
local lastPunch = 0
local debounce = false
script.Parent.Activated:Connect(function(hit)
if debounce then return end
if tick() - lastPunch > 1.5 then
currentPunch = 0
end
debounce = true
if currentPunch == 0 then
local rightPunch = hum:LoadAnimation(script:WaitForChild("RightPunch"))
rightPunch:Play()
wait(0.4)
hitboxEvent:FireServer(Vector3.new(3,3,2), Vector3.new(2), 20, 0.3)
task.wait(0.7)
debounce = false
elseif currentPunch == 1 then
local leftPunch = hum:LoadAnimation(script:WaitForChild("LeftPunch"))
leftPunch:Play()
wait(0.4)
hitboxEvent:FireServer(Vector3.new(3,3,2), Vector3.new(2), 20, 0.3)
task.wait(0.7)
debounce = false
elseif currentPunch == 2 then
local rightPunch = hum:LoadAnimation(script:WaitForChild("RightPunch"))
rightPunch:Play()
wait(0.4)
hitboxEvent:FireServer(Vector3.new(3,3,2), Vector3.new(2), 20, 0.3)
task.wait(0.7)
debounce = false
end
if currentPunch == 2 then
currentPunch = 0
else
currentPunch += 1
end
lastPunch = tick()
end)
end)
And it works when i just use it from StarterPack.
But it doesn’t when cloning it.
Tool clones but it’s not working.And there is no errors.