I’m trying to create a simple dummy system, where a dummy can be attacked for xp and gold. In concept the idea is very simple; however, I’ve run into one issue. The loop in the respawn function doesn’t run the first time its called for any dummy as in even If I’ve already called the function multiple times for one dummy, the loop still wont run on the first function call of any other dummy. In essence, I want to know if I am either overlooking something extremely obvious or if this is a bug?
I can guarantee that the there are children to dummy.Stats.DmgDealt which are Int Values even on the first run through that i’m referring to.
For fixes I’ve tried force running the function for each dummy when the the server loads.
In fact, ive done so in many ways, such as simply calling the function and dropping the dummies health to 0 while adding int value tags to under the dummy.Stats.DmgDealt. In the end even using this roundabout method the first time I manually attacked the dummy and it died, the loop did not run.
Just to humor myself I even tried moving the function to a module script to no avail.
local dummies = game.Workspace:WaitForChild("DummiesFolder")
local DL = game:GetService("ReplicatedStorage"):WaitForChild("BindableEvents"):WaitForChild("DummyLoot")
local DummyModule = require(script.Parent.DummyRespawn)
local function respawn(dummy, waitTime)
local dmg = {}
for i,v in pairs(dummy.Stats.DmgDealt:GetChildren()) do
print("Test")
if v:IsA("IntValue") then
local plrTable = {v.Name, v.Value}
print (plrTable[1] .. ":" .. plrTable[2])
table.insert(dmg, plrTable)
end
v:Destroy()
end
DL:Fire(dummy.Stats.Level.Value, dmg)
wait(waitTime)
dummy.Stats.Health.Value = dummy.Stats.Level.Value * 100
end
for i,v in pairs(dummies:GetChildren()) do
if v:IsA("Model") then
local dummy = v
local stats = dummy.Stats
local Health = stats.Health
local lvl = stats.Level
local hpFr = dummy.HPPart.BillboardGui.Frame.Frame
local hpText = dummy.HPPart.BillboardGui.Frame.TextLabel
Health.Changed:Connect(function()
hpFr.Size = UDim2.new(Health.Value/(lvl.Value*100),0,1,0)
hpText.Text = Health.Value .. "/" .. lvl.Value*100
if Health.Value <= 0 then
respawn(dummy, 5)
--DummyModule.Respawn(dummy, 5)
end
end)
Health.Value = 0 -- Test -- Loop Does Run; However, for the following actual attack it does not
end
end