#Trying to apply the damage on NPCs too but it's not working.

27 messages · Page 1 of 1 (latest)

latent pecan
#

Recently I've watched a tutorial video on youtube for a script that damages the player upon clicking on the player. When I try clicking on a NPC, the NPC isn't taking any damage. How am I supposed to do that?

  • ClickEvent is a RemoteEvent in ReplicatedStorage

LocalScript (StarterPlayerScripts):

local mouse = player:GetMouse()

local rs = game:GetService("ReplicatedStorage")
local clickEvent = rs:WaitForChild("ClickEvent")

mouse.Button1Down:Connect(function()
    local model = mouse.Target:FindFirstAncestorOfClass('Model')
    
    if model then
        local clickedPlayer = game.Players:GetPlayerFromCharacter(model)
        
        if clickedPlayer then
            print(clickedPlayer)
            clickEvent:FireServer(clickedPlayer)
        end
    end
end)```

**Script (ServerScriptServices)**:

```local rs = game:GetService('ReplicatedStorage')
local clickEvent = rs:WaitForChild('ClickEvent')

local damageAmount = 10

clickEvent.OnServerEvent:Connect(function(player, clickedPlayer)
    clickedPlayer.Character.Humanoid:TakeDamage(damageAmount)
end)```
nimble valley
#

Umm

#

Humoid?

latent pecan
#

where

nimble valley
#

Idk man

latent pecan
#

there is no humoid but ok

candid hedge
#

check the video embarrassedman

latent pecan
#

i did

#

i applied everything in the video to studio

#

still not working on NPCs

candid hedge
#

did u check the upload date

#

prob outdated

latent pecan
#

it's made last year

#

it works on players tho

candid hedge
#

does ur npc even have health

ember zincBOT
#

studio** You are now Level 2! **studio

latent pecan
#

yeah?

ember zincBOT
#

studio** You are now Level 1! **studio

candid hedge
#

k

#

are u attacking the npc or is the npc attacking u

latent pecan
#

im attacking to the npc

#

trying to deal damage by clicking on it

#

no any gears

#

just normally clicking

#

well im afk rn

nimble valley
#

@candid hedge doesnt it need to be humnoid?

candid hedge
#

ya humanoid