I’ve already made a topic about this script but that was focused more on the SuperEnemy itself, I’m now trying to implement the higher rewards for defeating said SuperEnemy
My script works and gives SuperReward but only for 2 SuperEnemy kills then it just gives NormalReward EXP and Gold rewards
I’ve been fiddling with script:Remove() vs script:Destroy() but that really didn’t change anything
It’s weird because its only the SuperReward function that breaks, not the NormalReward function and I’m wondering if it has something to do with how it respawns. Any help is appreciated.
Here’s what I have:
local Humanoid = script.Parent.Enemy
local EXPdisplay = game.StarterGui.EXPAmountDisplay
local chance = math.round(100/75)
local function NormalReward()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Exp.Value = Leaderstats.Exp.Value + 20
Leaderstats.Gold.Value = Leaderstats.Gold.Value + 15
wait(0.1)
script:Destroy()
end
end
end
end
local function SuperReward()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Exp.Value = Leaderstats.Exp.Value + 75
Leaderstats.Gold.Value = Leaderstats.Gold.Value + 50
wait(0.1)
script:Destroy()
end
end
end
end
local function SuperEnemy()
if not Humanoid then return end
if math.random(chance) == 1 and Humanoid.MaxHealth == 15 then
Humanoid.MaxHealth *= 2.5
Humanoid.Health = Humanoid.MaxHealth
local sparkles = Instance.new("Sparkles")
sparkles.Parent = script.Parent:FindFirstChild("Torso")
return true
end
return false
end
local isSuperEnemy = SuperEnemy()
if isSuperEnemy then
Humanoid.Died:Connect(SuperReward)
else
Humanoid.Died:Connect(NormalReward)
end
You have two functions for Reward, you could replace them with one function instead, and that could help you debug the problem better
local function Reward(exp, gold)
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Exp.Value = Leaderstats.Exp.Value + exp
Leaderstats.Gold.Value = Leaderstats.Gold.Value + gold
wait(0.1)
script:Destroy()
end
end
end
end
if isSuperEnemy then
Humanoid.Died:Connect(function() Reward(75, 50) end) --lambda functions so you can provide arguments
else
Humanoid.Died:Connect(function() Reward(20, 15) end)
end
I’d personally recommend not having this script under each Enemy, and instead have one script that runs a function for each Enemy when they are created. There could be a chance that this script isn’t being initialized under the SuperEnemy somehow
The chance is mainly for testing im not worried about that, but the respawning is handled in another script within the enemy
There also is another problem where once the enemy has become a SuperEnemy and dies, it’ll keep becoming a SuperEnemy and never become a normal enemy again.
I also had the thought that I should combine the respawning script with the EXP script but im unsure on how that would go.
Here it is incase that helps, I will try to debug your inital suggestions though.
local Humanoid = script.Parent.Enemy
local Clone = script.Parent:Clone()
Humanoid.Died:Connect(function()
wait(5.5)
script.parent:Destroy()
Clone.Parent = game.Workspace
end)