Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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)
0
do i put this in the local script themaxogamer 58 — 3y
0
Yeah. radiant_Light203 1166 — 3y
0
so i put the code in but its not working can you have the look at it https://gyazo.com/154433dafd112bfe01f48f9ca49ad9e8 themaxogamer 58 — 3y
View all comments (2 more)
0
What exactly isn't working? radiant_Light203 1166 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

https://gyazo.com/e15299a6b6e9850e0d92478c10e1b9e4

heres how it looks

Answer this question