Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with weapon script?

The problem with this script is that if you don't attack while you're moving, sometimes it's like the .Touched doesn't work therefore no damage is done.

local player = game.Players.LocalPlayer
local animation = script:WaitForChild("Animation")
local activated = false
local played = false
local Settings = script.Parent:WaitForChild("Settings")
local dmg = Settings:WaitForChild("Damage")

function play()
	played = true
	local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
	animationTrack:Play()
	Settings:WaitForChild("Sound1"):Play()
	wait(0.2)
	played = false
end	

script.Parent.Activated:connect(play)

function damage(hit)
	activated = true	
	if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent.Name ~= player.Name and player.Character:FindFirstChild("Humanoid").Health ~= 0 and activated == true and played == true then
	hit.Parent:FindFirstChild("Humanoid"):TakeDamage(dmg.Value)
	Settings:WaitForChild("Sound2"):Play()
	end
	wait(0.2)
	activated = false
	played = false
end
script.Parent.Handle.Touched:connect(damage)

function untouch()
	activated = false
	played = false
end
script.Parent.Handle.TouchEnded:connect(untouch)

1 answer

Actually, make a new script and do the following

--Of course you put your version, this is just to demostrate
function damage(hit)
local humanoided = hit.Parent:FindFirstChild("Humanoid")
If humanoid and hit.Parent.Name ~= "script.Parent.Name"  Then 
for i = 1, 10 do
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -1
end
end


--MAKE SURE TO NAME YOUR DAMAGE SCRIPT. In your main script do.

Damage = script.Damage:Clone()
Damage.Parent = Name of part

This discussion is preserved as it was. New answers, comments, and votes are closed.