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

Can anybody help me with this localscript? I'm trying to fire a server event when an NPC is killed.

Asked by 3 years ago
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local KillXPGainEvent = ReplicatedStorage:WaitForChild("KillXPGain")

local Humanoid = script.Parent:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()

print("Player killed a zombie!)

    KillXPGainEvent:FireServer()

end)

I'm making a zombies game and I'm trying to use a localscript to to fire a server event when a zombie is killed. I have fired the event trying other methods and it works but when I kill the zombie it doesn't register, I tried getting it to print after killing the zombie to troubleshoot but it won't print.

I'm pretty new to this so forgive me if i missed something trivial.

0
can you show me the server script? GameBuilderLol 58 — 3y
0
Hello, please what is parent of this script, where is it placed? I think this may be the problem BeautifulAuraLover 371 — 3y
0
The parent of the script was the Zombie but it's OK now I managed to create a workaround so my problem is solved. Thank you for trying to help anyway is there anyway I can mark this thread as solved or should I just delete it? preyslushrapier 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local KillXPGainEvent = ReplicatedStorage:WaitForChild("KillXPGain")

local XPPerKill = 5

KillXPGainEvent.OnServerEvent:Connect(function(Player)

    local leaderstats = Player:WaitForChild("leaderstats")

    print("FoundLeaderstats")

    local EXP = leaderstats:WaitForChild("EXP")

    print("FoundEXP")

    EXP.Value = EXP.Value + XPPerKill
end)

This is the server script.

Ad

Answer this question