I'm trying to make a kill counter for my game WizardWars and so far I'm stuck and I don't know what to do I have LeaderStats and I clone my fireball.What I'm thinking is check if the ball is hit and hit.Parent:WaitForChild("Humanoid").Health and if the health = 0.But I'm stuck on how I can check the PlayerStats Because the Damage Script is in the Cloned FireBall.
So if anyone could help me that would be great!
Edit:It says you can't get owner is not a member of part here my update
wait(1) local Kills = script.Parent.Owner.Value.leaderstats.Kills local Dam = 10 -- Changre if want new damages script.Parent.Touched:connect(function(hit) print(hit.Parent) local Human = hit.Parent:WaitForChild("Humanoid") if Human then print("Hit") Human:TakeDamage(10) if Human.Health <= 0 then Kills = Kills + 1 end wait() script.Parent:Destroy() end wait(3) script.Parent:Destroy() end)
This is in a local script in the fireball.
The script doing damage needs to be given the player who cast it (otherwise how can it know who to attribute any kills to?). (By the way, don't use WaitForChild
, since the thing the fireball hit might not ever get a Humanoid.) To amend your idea:
local kills = script.Parent.Owner.Value.leaderstats.Kills script.Parent.Touched:Connect(function(hit) if not hit.Parent then return end local hum = hit.Parent:FindFirstChild("Humanoid") if not hum or hum.Health <= 0 then return end -- not alive --if not game.Players:GetPlayerFromCharacter(hit.Parent) then return end -- uncomment this line if you only want to record kills on players rather than both players and NPCs hum:TakeDamage(damage) if hum.Health <= 0 then --killed something kills.Value = kills.Value + 1 end end)
In whatever script casts the fireball, it would need to create the Owner ObjectValue and set its value to the casting player before the fireball script runs (ex before the fireball is parented to the workspace). ex:
--Whereever it is that you clone the fireball, ex: local fireball = game.ReplicatedStorage.Fireball:Clone() --add something like this: local owner = Instance.new("ObjectValue") owner.Value = player -- 'player' must be defined elsewhere. If you do this in a RemoteEvent, then you should use that player. If this is in a LocalScript (which isn't compatible with FE but otherwise can work), then you could just use the LocalPlayer. owner.Parent = fireball -- You must parent the fireball to something already; be sure to do that last. ex: fireball.Parent = workspace