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

How to get enemy player in this situation?

Asked by 2 years ago

I have come upon a halt in my script.

There isn't any bugs or anything, its just I cant figure out how I can get it in this situation!

Here is the script:

local EventE = game:GetService("ReplicatedStorage").Remotes.RemoteE
local DisableAttack = game:GetService("ReplicatedStorage").SpecialRemotes.DisableAttack
local EnableAttack = game:GetService("ReplicatedStorage").SpecialRemotes.EnableAttack
local TweenService = game:GetService("TweenService")
local Animations = script:FindFirstChild("Animations")
local Sounds = script:FindFirstChild("Sounds")
local Particles = script:FindFirstChild("Particles")
local EDamage = 20

game:GetService("Players").PlayerAdded:Connect(function(player)
    local cooldown = Instance.new("NumberValue")
    cooldown.Value = tick()
    cooldown.Name = "Cooldown"
    cooldown.Parent = player
end)

EventE.OnServerEvent:Connect(function(player,cooldown)
    if tick() - player.Cooldown.Value > cooldown then
        player.Cooldown.Value = tick()
        local char = player.Character
        local hum = char.Humanoid
        local humRP = char.HumanoidRootPart
        local Head = char.Head
        local hasHit = false
        local tweenActive = true
        local torso = char.Torso
        local Run = hum:LoadAnimation(Animations.Run1)
        local React = hum:LoadAnimation(Animations.React)
        local Sound = Sounds.Reaction:Clone()
        local Particle = Particles.SSJParticle:Clone()
        React:Play()
        hum.WalkSpeed = 0
        Sound.Parent = humRP
        Sound:Play()
        wait(.25)
        Particle.Parent = Head
        wait(.5)
        local tween = TweenService:Create(humRP,TweenInfo.new(.75,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0),{CFrame = humRP.CFrame * CFrame.new(0,0,-50)})
        React.Stopped:Connect(function()
            Particle:Destroy()
            tween:Play()
            Run:Play()
            tweenActive = true
            Sound.Ended:Connect(function()
                Sound:Destroy()
            end)
            for _, i in pairs(char:GetChildren()) do
                if i:IsA("BasePart") then
                    i.Touched:Connect(function(hit)
                        if hasHit == false and tweenActive == true then
                            if hit.Parent then
                                if hit.Parent:FindFirstChild("Humanoid") then
                                    print("found character!")
                                    local hitHum = hit.Parent.Humanoid
                                    local hitHRP = hit.Parent:FindFirstChild("HumanoidRootPart")
                                    local UppercutPlr = hum:LoadAnimation(Animations.UppercutPlr)
                                    local UppercutEnemy = hitHum:LoadAnimation(Animations.UppercutEnemy)
                                    local enemyPlr = game.Players:GetPlayerFromCharacter(hit.Parent)
                                    tweenActive = false
                                    hasHit = true
                                    tween:Pause()
                                    hitHum:TakeDamage(EDamage)
                                    Run:Stop()
                                    DisableAttack:FireClient(enemyPlr)
                                    UppercutPlr:Play()
                                    UppercutEnemy:Play()
                                    humRP.CFrame = hitHRP.CFrame * CFrame.new(0,0,-3)
                                    humRP.CFrame = CFrame.new(humRP.Position, hitHRP.Position)
                                    humRP.Anchored = true
                                    hitHRP.Anchored = true
                                    UppercutPlr.Stopped:Connect(function()
                                        hum.WalkSpeed = 16
                                        humRP.Anchored = false
                                        hitHRP.Anchored = false
                                        EventE:FireClient(player)
                                        EnableAttack:FireClient(enemyPlr)
                                    end)
                                end
                            end
                        end
                    end)
                end
            end
            tween.Completed:Connect(function()
                if hasHit == false then
                    Run:Stop()
                    tweenActive = false
                    hum.WalkSpeed = 16
                    EnableAttack:FireClient(player)
                end
            end)
        end)
    end
end)

The script is in ServerScriptService, and the script is a (very obvious) server script.

The problem is since I cant get the enemy player, I only have the player. This results in MORE problems including the player being unable to use a move after used. It's weird.

Any help would be appreciated!

For more detail in what any of this stuff is, please ask, and I can kindly provide.

Thank you for listening.

I hope I can count on you!

0
Isn't the enemy player just enemyPlr? rabbi99 714 — 2y
0
Yes, except the part that isnt working is Tween.Completed:Connect(function(). LikeableEmmec 470 — 2y
0
I FEEL SO DUMB!!! I didnt need the enemy player because the enemy player didnt exist in the first place! The enemy player only existant inside the hit function! LikeableEmmec 470 — 2y

Answer this question