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

how can i make the animation play when tool is equipped?

Local script :

	local Player = game:GetService("Players")
local rp = game:GetService("ReplicatedStorage")
local KiritosSword = rp:WaitForChild("KiritosSword")
local tool = script.Parent
local UIS = game:GetService("UserInputService")

local debounce = false
local cooldown = 1

UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then	 
	return
	
		
		

elseif input.KeyCode == Enum.KeyCode.F and debounce == false then
	debounce = true

	KiritosSword:FireServer()
	

	
	end
end)

KiritosSword.OnClientEvent:Connect(function()

	wait(cooldown)
	debounce = false
end)

And Script

local rp = game:GetService("ReplicatedStorage")
	local KiritosSword = rp:WaitForChild("KiritosSword")

local Animation = game.Workspace.Animations:WaitForChild("Swing") -- Find the 			 
     animation
local tool = script.Parent

local Blade = script.Parent:WaitForChild("Blade")
local Particle1 = Blade:WaitForChild("Lightning1")
local Particle2 = Blade:WaitForChild("Lightning2")
local Particle3 = Blade:WaitForChild("ParticleEmitter")


KiritosSword.OnServerEvent:Connect(function(Player)
    local Character = Player.Character 
    local Humanoid = Character:FindFirstChild("Humanoid")
    local Swing = Humanoid:LoadAnimation(Animation) 

	


    Swing:Play() 
    KiritosSword:FireClient(Player)
	wait(1)
	Particle1.Enabled = true
	Particle2.Enabled = true
    Particle3.Enabled = true


end)

2 answers

Okay so, animations automatically replicate to the server so there's no need to play them on the server.

Also, nest the UserInputFunction in the tool's equipped function like so:

local UserInputService = game:GetService("UserInputService")
local Debounce = false
local InputFunction

script.Parent.Equipped:Connect(function()
	InputFunction = UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent) -- in your case GameProcessedEvent is IsTyping
		if GameProcessedEvent or debounce == true then return end
		if Input.KeyCode = Enum.KeyCode.F and debounce == false then
			debounce = true
			-- rest of your code
		end
	end)
	-- rest of your code
end)

And disconnect the function on tool unequip so it doesn't keep running on input.

script.Parent.Unequipped:Connect(function()
	InputFunction:Disconnect()
end)

6 comments

0

do i put this in the local script

0

Yeah.

0

so i put the code in but its not working can you have the look at it https://gyazo.com/154433dafd112bfe01f48f9ca49ad9e8

0

What exactly isn't working?

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