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

NPC that does damage affected by leaderstats? [closed]

Asked by 5 years ago

Im using the roblox free model, Drooling Zombie that does damage within a module script. Tried having the script fire a remote event that gives me the error " FireServer can only be called from the client"

Tried to identify the player through the touched event and through the character but that didnt work either, I got the same error as you would if you used Localplayer in a normal script. Heres my code :

-- Setup arms damage
    local canHit = true
    local lastHit = os.time()
    local damagegive = configs["Damage"]
    local function handleHit(other)
        if canHit then
            if other and other.Parent and other.Parent.Name ~= "Drooling Zombie" and other.Parent:FindFirstChild("Humanoid") then
                local enemy = other.Parent              
                local player = game.Players:GetPlayerFromCharacter(other)
                local stats = player.playerstats
                local defense = stats.defense
                if enemy.Humanoid.WalkSpeed > 0 then
                    enemy.Humanoid:TakeDamage(damagegive-defense.Value)
                    canHit = false
                    end 
            end
        else
            local now = os.time()
            if now - lastHit > configs["DamageCooldown"] then
                lastHit = now
                canHit = true
            end
        end
    end 
    local leftHitConnect, rightHitConnect
    leftHitConnect = model:FindFirstChild("Left Arm").Touched:connect(handleHit)
    rightHitConnect = model:FindFirstChild("Right Arm").Touched:connect(handleHit)

Note : The game im creating has stats and such and I want the defense stat within the leaderstats as most would call it to subtract from the damage dealt. Any clues on how I could fix this problem? Also, whats a better way of having the script identify other enemies? Im not even sure whatthe if other and other.Parent... part does. God bless friends.

0
Please do not ask for help with free models. Use your own code and post questions regarding it. Gey4Jesus69 2705 — 5y

Closed as Not Constructive by Gey4Jesus69 and DinozCreates

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?