I am trying to program weapons you can use in a game I made.
My code only runs on one client and doesn’t hurt them on their own screen. I have no idea how to fix it
I looked for solutions on dev forums, but only found some discussions about GUI glitches.
Here’s the code;
local plr = game.Players.LocalPlayer
local chr = plr.CharacterAdded:Wait()
local hum = chr:WaitForChild("Humanoid")
local item = script.Parent
local attacking = 0
local animation2 = script.Parent.Slice
local track2 = hum:LoadAnimation(animation2)
track2.Priority = "Action"
local handle = item.Handle
local sound1 = script.Parent.explosion
local sound2 = script.Parent["knife swing"]
local db = 0
item.Activated:Connect(function()
if db == 0 then
db = 1
track2:Play()
wait(2)
sound2:Play()
attacking = 1
wait(2)
db = 0
end
end)
track2.Stopped:Connect(function()
attacking = 0
end)
handle.Touched:Connect(function(hit)
if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
if attacking == 1 then
hit.Parent.Humanoid.Health = (hit.Parent.Humanoid.Health - 70)
local explode = Instance.new("Explosion")
explode.Parent = hit
sound1:Play()
attacking = 0
end
end
end)