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

ok so how can i make my sword not hit and give strenght while the animation is playing?

------------------< variables >----------------
local uis = game:GetService("UserInputService")
local saber = script.Parent
local p = game.Players.LocalPlayer
local l = p.leaderstats
local equipped = false
local textBox = game.StarterGui.Strenght.TextLabel
local anim = script.Parent:WaitForChild("SwingAnimation")
------------------< code >---------------------
saber.Equipped:Connect(function()
	equipped = true
end)
saber.Unequipped:Connect(function()
	equipped = false
end)
uis.InputBegan:Connect(function(input1)
	local mouseIn1 = input1.UserInputType
	if equipped == true and mouseIn1 == Enum.UserInputType.MouseButton1 then
		wait(0.6)
		l.Strenght.Value = l.Strenght.Value + 5
		local loadedAnim = p.Character.Humanoid:LoadAnimation(anim)
		loadedAnim:Play()
	end
end)

this is my script it works totally fine, but i want to know how to make the sword not give any strenght while the animation is playing any help is apriciated

2 comments

0

Could use an if statement to not run any damage code when the animation is playing. Think you could use this https://developer.roblox.com/en-us/api-reference/property/AnimationTrack/IsPlaying

0

ok so i did this "if anim.IsPlaying == true and mouseIn1 == Enum.UserInputType.MouseButton1 then wait(0.6) end" and it gives me an error

1 answer

✓ Accepted answer

Try to switch like that

	        local loadedAnim = p.Character.Humanoid:LoadAnimation(anim)
	        loadedAnim:Play()
		wait(2)
l.Strenght.Value = l.Strenght.Value + 5

edit:

local uis = game:GetService("UserInputService")
	local saber = script.Parent
	local p = game.Players.LocalPlayer
	local l = p.leaderstats
	local equipped = false
	local textBox = game.StarterGui.Strenght.TextLabel
	local anim = script.Parent:WaitForChild("SwingAnimation")
	local hitt = 1
	------------------< code >---------------------
	saber.Equipped:Connect(function()
	    equipped = true
	end)
	saber.Unequipped:Connect(function()
	    equipped = false
	end)
	uis.InputBegan:Connect(function(input1)
	    local mouseIn1 = input1.UserInputType
	    if equipped == true and mouseIn1 == Enum.UserInputType.MouseButton1 then
			if hitt == 1 then
	        	l.Strenght.Value = l.Strenght.Value + 5
	        	local loadedAnim = p.Character.Humanoid:LoadAnimation(anim)
	        	loadedAnim:Play()
				hitt = 0
				wait(1)
				hitt = 1
			end
	    end
	end)

9 comments

0

one second

0

ok so the player can still hit while the animation is playing. this is my problem. ill give you a link of a video of my problem

0

sorry for the bad quality but i'm sure you can understand what's going on https://imgur.com/a/fLocq5Y

0

got it, i think i fixed it, i'll put the script in a new comment

0

nvm, i edited this comment, let me know if is working

0

if you don't get any errors and you can still hit while is animating, switch the wait time from "if hitt == 1 then"...

0

what is the "hitt " variable supposed to mean? the time of the animation or what? i don't really get it

0

is like ammo, you need to wait until you reload to shoot again

0

thanks a lot

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