I'm attempting to give the player rewards for defeating enemies, but for whatever reason the script doesn't reward the player at all.

This is a LocalScript:

local Humanoid = script.Parent.Humanoid
local Torso = script.Parent.Torso
function HasDied() 
local player = game.Players.LocalPlayer
local tag = Torso:findFirstChild("Tag") 
	if tag ~= nil then
print("PassedTest1") 
		if tag.Value ~= nil then 
print("PassedTest2")
player.leaderstats1.Ryo.Value = player.leaderstats1.Ryo.Value + 999
player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + math.random(50,200)
wait(0.1)
script:remove()
			end 
		end 
	end 
Humanoid.Died:connect(HasDied) 

The Tag is not nil, and is destroyed 5 seconds after being created. Each time an enemy, or any humanoid with a torso gets hit(And yes the enemies have their Torso named 'Torso') The hit target gets a StringValue in their Torso named 'Tag'. This StringValue's value is the name of the player who hit the enemy. There is no error in the output, and no message from the prints.

4 comments

0

remove is deprecated, switch to Destroy. findFirstChild is deprecated, switch to FindFirstChild. connect is deprecated, switch to Connect

0

I don't know if it's supposed to happen or if it's just me or something but deprecated stuff actually works for me these days

0

I'm assuming that it's left operational so that old projects don't break.

0

The deprecated edits didn't change anything, the script is still broken?