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

Enemy on Died:connect rewards not being rewarded after dying?

Asked by 6 years ago

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:

01local Humanoid = script.Parent.Humanoid
02local Torso = script.Parent.Torso
03function HasDied()
04local player = game.Players.LocalPlayer
05local tag = Torso:findFirstChild("Tag")
06    if tag ~= nil then
07print("PassedTest1")
08        if tag.Value ~= nil then
09print("PassedTest2")
10player.leaderstats1.Ryo.Value = player.leaderstats1.Ryo.Value + 999
11player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + math.random(50,200)
12wait(0.1)
13script:remove()
14            end
15        end
16    end
17Humanoid.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.

0
remove is deprecated, switch to Destroy. findFirstChild is deprecated, switch to FindFirstChild. connect is deprecated, switch to Connect User#19524 175 — 6y
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 mudathir2007 157 — 6y
0
I'm assuming that it's left operational so that old projects don't break. k3du53 162 — 6y
0
The deprecated edits didn't change anything, the script is still broken? sactman64 7 — 6y

Answer this question