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

My attack script not work and not have error in output, Why? [closed]

Asked by 6 years ago

Hello i'm trying to make a attack script. The script works in studio but in the game not work :/ here it's the script:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character
local debounceQ = true
local debounceTime = 0.5
local debounceE = true

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q then
        if debounceQ == true then
            if Player.CanAttack.Value == true then
                if Character ~= nil then
                    if Character:FindFirstChild("Humanoid") then
                        debounceQ = false
                        local Humanoid = Character.Humanoid
                        local Anim1 = Humanoid:LoadAnimation(script.AttackQ)
                        local Anim2 = Humanoid:LoadAnimation(script.AttackE)
                        Anim1:Play()
                        Player.CanDamageQ.Value = true
                        wait(debounceTime)
                        Player.CanDamageQ.Value = false
                        wait(0.4)
                        debounceQ = true
                    end
                end
            end
        end
    end
end)

Character:WaitForChild("Left Arm").Touched:connect(function(hit)
    if Player.CanDamageQ.Value == true then
        if hit.Parent:FindFirstChild("Humanoid") then
            local hum = hit.Parent.Humanoid
            hum:TakeDamage(5)
        end
    end
end)

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        if debounceE == true then
            if Player.CanAttack.Value == true then
                if Character ~= nil then
                    if Character:FindFirstChild("Humanoid") then
                        debounceE = false
                        local Humanoid = Character.Humanoid
                        local Anim1 = Humanoid:LoadAnimation(script.AttackQ)
                        local Anim2 = Humanoid:LoadAnimation(script.AttackE)
                        Anim2:Play()
                        Player.CanDamageE.Value = true
                        wait(debounceTime)
                        Player.CanDamageE.Value = false
                        wait(0.4)
                        debounceE = true
                    end
                end
            end
        end
    end
end)

Character:WaitForChild("Right Arm").Touched:connect(function(hit)
    if Player.CanDamageE.Value == true then
        if hit.Parent:FindFirstChild("Humanoid") then
            local hum = hit.Parent.Humanoid
            hum:TakeDamage(5)
        end
    end
end)

pls help me!

0
USE WAITFORCHILD SO IT CAN LOAD Subaqueously 11 — 6y
0
"The script works in studio but in the game not work" is very broad. hiimgoodpack 2009 — 6y

Closed as Non-Descriptive by hiimgoodpack, abnotaddable, and Goulstem

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 6 years ago

I guess it's a server-side script... Well, I think the error is that you got the player with

game.Players.LocalPlayer

which is wrong.

LocalPlayer can only be used in LocalScripts, you have to use a way to get the player. Here's how I would do it:

game.Players.PlayerAdded:Connect(function(Player)
    local UIS = game:GetService("UserInputService")
    local Mouse = Player:GetMouse()
    local Character = Player.Character
    local debounceQ = true
    local debounceTime = 0.5
    local debounceE = true

    UIS.InputBegan:connect(function(input)
        if input.KeyCode == Enum.KeyCode.Q then
            if debounceQ == true then
                if Player.CanAttack.Value == true then
                    if Character ~= nil then
                        if Character:FindFirstChild("Humanoid") then
                            debounceQ = false
                            local Humanoid = Character.Humanoid
                            local Anim1 = Humanoid:LoadAnimation(script.AttackQ)
                            local Anim2 = Humanoid:LoadAnimation(script.AttackE)
                            Anim1:Play()
                            Player.CanDamageQ.Value = true
                            wait(debounceTime)
                            Player.CanDamageQ.Value = false
                            wait(0.4)
                            debounceQ = true
                        end
                    end
                end
            end
        end
    end)

    Character:WaitForChild("Left Arm").Touched:connect(function(hit)
        if Player.CanDamageQ.Value == true then
            if hit.Parent:FindFirstChild("Humanoid") then
                local hum = hit.Parent.Humanoid
                hum:TakeDamage(5)
            end
        end
    end)

    UIS.InputBegan:connect(function(input)
        if input.KeyCode == Enum.KeyCode.E then
            if debounceE == true then
                if Player.CanAttack.Value == true then
                    if Character ~= nil then
                        if Character:FindFirstChild("Humanoid") then
                            debounceE = false
                            local Humanoid = Character.Humanoid
                            local Anim1 = Humanoid:LoadAnimation(script.AttackQ)
                            local Anim2 = Humanoid:LoadAnimation(script.AttackE)
                            Anim2:Play()
                            Player.CanDamageE.Value = true
                            wait(debounceTime)
                            Player.CanDamageE.Value = false
                            wait(0.4)
                            debounceE = true
                        end
                    end
                end
            end
        end
    end)

    Character:WaitForChild("Right Arm").Touched:connect(function(hit)
        if Player.CanDamageE.Value == true then
            if hit.Parent:FindFirstChild("Humanoid") then
                local hum = hit.Parent.Humanoid
                hum:TakeDamage(5)
            end
        end
    end)
end)

0
@XenofTheInmortal still not work in the game ScripterHalper -10 — 6y
0
Try to use WaitForChild maybe it fired before the game generated. SulaymanArafat 230 — 6y
Ad