Hello!
I’ve started a new game and I’m trying to implement abilities and levels and all that. So when I use my abilities to kill an NPC it won’t award any EXP or Gold. Yet when I just kill him with my swing attack it does give me the EXP and Gold. Could someone help me with this problem? Here is the script that awards the EXP and Gold.
local Humanoid = script.Parent.Humanoid
function PwntX_X()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Data = tag.Value:findFirstChild("Data")
if Data ~= nil then
Data.Gold.Value = Data.Gold.Value + 50
Data.Exp.Value = Data.Exp.Value + 100
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)
-HystericalBinky
1 Like
local Humanoid = script.Parent.Humanoid
function PwntX_X()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Data = tag.Value:findFirstChild("Data")
if Data ~= nil then
Data.Gold.Value = Data.Gold.Value + 50
Data.Exp.Value = Data.Exp.Value + 100
wait(0.1)
end
end
end
end
Humanoid.Died:connect(PwntX_X)
try it without the script:remove()?
Change remove()
to Destroy()
Edit: You have some spelling mistakes as well:
-
findFirstChild
should be FindFirstChild
tried that, still doesn’t give exp when using the abilities.
Most likely is because your ability does not add a creator tag when damaging, you’ll have to do what the swing attack does by adding a creator tag that goes away after a short time when damaging an enemy
edit: My english is brilliant
Edit2: findFirstChild
is a deprecated method of FindFirstChild
, both do the same thing so it’s not that
1 Like
I have read your script multiple times and have now come to the assumption that the problem is in the script responsible for damaging and creating the “creator” value in the NPC, either it does not create it or it creates it somewhere else, make sure that is correct.
Another problem I noticed
:remove() is a deprecated method of destroying an object, use :Destroy() instead as it prevents memory leaks
I did as u said and it still doesn’t work for some reason. Here’s the script that damages and stuff where I added the tag to. Can u maybe check if I did something wrong? (This is basically the same in all the other abilities to)
script.Parent.OnServerEvent:Connect(function(plr)
local Projectile = game.ReplicatedStorage.Gryphon.Slash_Skill1:Clone()
Projectile.Parent = workspace
Projectile.CanCollide = false
Projectile.Anchored = false
Projectile.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-1.5) * CFrame.fromEulerAnglesXYZ(0,3.2,0)
Projectile.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
local HitEffect = game.ReplicatedStorage.Gryphon.Ball_Skill1:Clone()
HitEffect.Parent = workspace
HitEffect.CFrame = hit.CFrame
HitEffect.CanCollide = false
HitEffect.Anchored = true
Projectile:Destroy()
TagHumanoid(Humanoid, vPlayer)
hit.Parent.Humanoid:TakeDamage(25)
wait(0.25)
UntagHumanoid(Humanoid)
for i = 1,18 do
wait(.05)
HitEffect.Size = HitEffect.Size + Vector3.new(1,1,1)
HitEffect.Transparency = HitEffect.Transparency + 0.1
end
HitEffect:Destroy()
end
end)
local BV = Instance.new("BodyVelocity",Projectile)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 70
wait(0.1)
Projectile.Transparency = 0.1
wait(0.01)
Projectile.Transparency = 0.2
wait(0.01)
Projectile.Transparency = 0.3
wait(0.01)
Projectile.Transparency = 0.4
wait(0.01)
Projectile.Transparency = 0.5
wait(0.01)
Projectile.Transparency = 0.6
wait(0.01)
Projectile.Transparency = 0.7
wait(0.01)
Projectile.Transparency = 0.8
wait(0.01)
Projectile:Destroy()
end)
function TagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
Looking closely it seems like you don’t make a variable for Humanoid
, so that’s always going to parent it to nil
Try this?
local function TagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
local function UntagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
script.Parent.OnServerEvent:Connect(function(plr)
local Projectile = game.ReplicatedStorage.Gryphon.Slash_Skill1:Clone()
Projectile.Parent = workspace
Projectile.CanCollide = false
Projectile.Anchored = false
Projectile.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-1.5) * CFrame.fromEulerAnglesXYZ(0,3.2,0)
Projectile.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and hit.Parent.Name ~= plr.Name then
local HitEffect = game.ReplicatedStorage.Gryphon.Ball_Skill1:Clone()
HitEffect.Parent = workspace
HitEffect.CFrame = hit.CFrame
HitEffect.CanCollide = false
HitEffect.Anchored = true
Projectile:Destroy()
TagHumanoid(Humanoid, vPlayer)
hit.Parent.Humanoid:TakeDamage(25)
wait(0.25)
UntagHumanoid(Humanoid)
for i = 1,18 do
wait(.05)
HitEffect.Size = HitEffect.Size + Vector3.new(1,1,1)
HitEffect.Transparency = HitEffect.Transparency + 0.1
end
HitEffect:Destroy()
end
end)
local BV = Instance.new("BodyVelocity",Projectile)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 70
wait(0.1)
Projectile.Transparency = 0.1
wait(0.01)
Projectile.Transparency = 0.2
wait(0.01)
Projectile.Transparency = 0.3
wait(0.01)
Projectile.Transparency = 0.4
wait(0.01)
Projectile.Transparency = 0.5
wait(0.01)
Projectile.Transparency = 0.6
wait(0.01)
Projectile.Transparency = 0.7
wait(0.01)
Projectile.Transparency = 0.8
wait(0.01)
Projectile:Destroy()
end)
Still doesn’t work for some reason.
Okay I see the 2nd issue, you don’t have a vPlayer variable, I think you meant plr
, so change
TagHumanoid(Humanoid, vPlayer)
To
TagHumanoid(Humanoid, plr)
It works! thanks a lot, now I just need to apply them to the other ability scripts but I think I can do that myself. Thanks a lot!
1 Like
Uhhh so I’m having problems implementing it into the other abilities. for some reason it does work with my 1st ability but not my 2nd ability? here’s the code of 1 of the 3 scripts. (there’s 3 attacks thats why there are 3 scripts)
local function TagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
local function UntagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
script.Parent.OnServerEvent:Connect(function(plr)
local Projectile = game.ReplicatedStorage.Gryphon.Slash_Skill21:Clone()
Projectile.Parent = workspace
Projectile.CanCollide = false
Projectile.Anchored = false
Projectile.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,2,-1.5) * CFrame.fromEulerAnglesXYZ(0,0,5.5)
Projectile.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
local HitEffect = game.ReplicatedStorage.Gryphon.Ball_Skill2:Clone()
HitEffect.Parent = workspace
HitEffect.CFrame = hit.CFrame
HitEffect.CanCollide = false
HitEffect.Anchored = true
Projectile:Destroy()
TagHumanoid(Humanoid, plr)
hit.Parent.Humanoid:TakeDamage(10)
wait(0.25)
UntagHumanoid(Humanoid)
for i = 1,18 do
wait(.05)
HitEffect.Size = HitEffect.Size + Vector3.new(2,2,2)
HitEffect.Transparency = HitEffect.Transparency + 0.1
end
HitEffect:Destroy()
end
end)
local BV = Instance.new("BodyVelocity",Projectile)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 100
wait(0.4)
Projectile.Transparency = 0.1
wait(0.01)
Projectile.Transparency = 0.2
wait(0.01)
Projectile.Transparency = 0.3
wait(0.01)
Projectile.Transparency = 0.4
wait(0.01)
Projectile.Transparency = 0.5
wait(0.01)
Projectile.Transparency = 0.6
wait(0.01)
Projectile.Transparency = 0.7
wait(0.01)
Projectile.Transparency = 0.8
wait(0.01)
Projectile:Destroy()
end)
Same issue, there’s no variable set up called Humanoid
, so it parents it to nil
You have to include this line
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
Inside of the touched event, look at the code I provided with the change to see how I did it
Alright! It fixed the bug thanks a lot!
2 Likes