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

[SOLVED] Punch can not create the random punch system?

Asked by 5 years ago
Edited 5 years ago

I can not make the random punch system, like it punches a left punch then a right punch and then a kick! help me

StarterCharacterScripts

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")

local ready = true

local function punch(inputObject, gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.Q and ready then
        punchEvent:FireServer()
        ready = false
        wait(0.5)
        ready = true
    end
end

UserInputService.InputBegan:Connect(punch)

ServerScriptService

math.randomseed(tick())

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"

local animations = {2634692328}

local function onPunchFired(plr)
    local char = game.Workspace:FindFirstChild(plr.Name)
    local humanoid = char.Humanoid
    local animation = Instance.new("Animation")
    local picked = math.random(1, #animations)
    animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
    local animTrack = humanoid:LoadAnimation(animation)
    animTrack:Play()
    local dmgScript = script.DmgScript:Clone()
    if picked == 1 then
        dmgScript.Parent = char.RightHand
    elseif picked == 2 then
        dmgScript.Parent = char.LeftHand
    end
    dmgScript.Disabled = false
    wait(0.4)
    dmgScript:Destroy()
end

punchEvent.OnServerEvent:Connect(onPunchFir
0
Put script you tried in message yHasteeD 1819 — 5y
0
math.random(3)? Picks a number that correlates with a certain animation. Audiimo 105 — 5y
0
Maybe not the best way but incredibly simple Audiimo 105 — 5y

Answer this question