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

How do I make animations work when I press Q in ROBLOX player?

Asked by
LawlR 182
6 years ago

Here is the download to the game: https://mega.nz/fm/Ua4EGBDZ When you press Q, you are meant to punch. It works in studio, but not in roblox player. It's an FE enabled game with r15 characters. It only gives one error in roblox player; "Infinite yield possible on ServerScriptService("Punch")", something like that, but you can see yourself.

1 answer

Log in to vote
1
Answered by 6 years ago

Well to start you need a local script. in this local script you will be able to press Q to punch, it will play the animation, and fire tuple arguments to the server to see if it should punch

The local script should be in StarterCharacterScripts, and should look something like this:

local UIS = game:GetService('UserInputService')
local RS = game:GetService('ReplicatedStorage')

local PunchEvent = RS:WaitForChild('PunchEvent')

local Punching = false
local Damaging = false

local Char = script.Parent
local Humanoid = Char.Humanoid
local RightHand = Char:WaitForChild('RightHand')

local PunchAnimation = Instance.new('Animation') -- define the animation instance, or make an animation instance

PunchAnimation.AnimationId = 'rbxassetid://67584958' -- if you have a new instance animation, make sure to set the right id

local Damage = 20 -- put damage here

UIS.InputBegan:connect(function(input)
    if input.KeyCode = Enum.KeyCode.Q then
        if not Punching then
            Punching = true
            Damaging = true
            local PunchTrack = Humanoid:LoadAnimation(PunchAnimation)
            PunchTrack:Play()
            PunchTrack.Stopped:wait()
            Punching = false
            Damaging = false
        end
    end
end)

RightHand.Touched:connect(function(hit)
    if hit.Parent:FindFirstChildOfClass('Humanoid') and Punching and Damaging then
        Damaging = false
        PunchEvent:FireServer(hit.Parent:FindFirstChildOfClass('Humanoid'), Damage)
    end
end)

now there should be an event in ReplicatedStorage and a server script in ServerScriptService. in this script should be something like this:

local PunchEvent = game:GetService('ReplicatedStorage'):WaitForChild('PunchEvent')

PunchEvent.OnServerEvent:connect(function(client, HumanoidToDamage, Damage)
    HumanoidToDamage:TakeDamage(Damage)
end)

this should allow for the animation to play, and the damage to be done

0
Why doesn't my game work? LawlR 182 — 6y
0
What do you mean? Qu4n7umZ 55 — 6y
0
I posted a link to the download of my game, it works in studio, but not in in-game. LawlR 182 — 6y
Ad

Answer this question