Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

3 comments

0

can you show me the server script?

0

Hello, please what is parent of this script, where is it placed? I think this may be the problem

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?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.