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

Is there any way to make this blocks of script any shorter?

It's sometimes confusing to read scripts this long.

script.Parent.Equipped:Connect(function(mouse)
	local wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)
	wield:Play()
		mouse.Button1Down:Connect(function()
			local wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)			
			local lunge = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Lunge)
			wield:Stop()
			lunge:Play()
		end)
		mouse.Button1Up:Connect(function()
			script.Parent.CanDamage.Value = true
			
			local wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)					
			local slash = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Slash)
			slash:Play()
			wait(1)
			slash:Stop()
			wield:Play()
			
			script.Parent.Blade.Touched:Connect(function(hit)
				if script.Parent.CanDamage.Value == true then
					script.Parent.CanDamage.Value = false
					hit.Parent.Humanoid:TakeDamage(100)
				end
			end)
		end)
end)

1 answer

✓ Accepted answer

Just store object in variables!

Weild = script.Wield --If your that lazy to save a few characters of code
Slash = script.Slash --Again, if your THAT lazy
Humanoid = game.Players.LocalPlayer.Character.Humanoid
--"game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)" changes to...
Humanoid:LoadAnimation(Wield)

Also, don't put ":Connect()" events within loops, functions, or other events; this may slow down your code and potentially crash!

end) --".Equipped:Connect" event

script.Parent.Blade.Touched:Connect(function(hit)
	--You get the idea
end)

If you have any questions or issues contact me. ;)

4 comments

0

uhm... i dont quite understand... im really sorry. :(

0

When you say "Wield =" or "Humanoid = " then it means that your giving a value to them. So if "Wield = script.Wield" then it means that just saying "Wield" is the same thing as saying "script.Wield"

0

i did (outside the equipped function). but the animation didn't run. :(

0

Weird. Just make sure that your variables are all pointing correctly to where the object is located! My guess for why it also might have not played is that you need to store "Humanoid:LoadAnimation(Wield)" or whatever into another variable which is what you scope ":Play()" to.

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