Stuck on leaderstats Problem?
I have tried putting a code in a tool whenever the humanoid is hit it goes to 0 health and also it gives you a certain amount of Cash, Xp, Kills.
But whenever I kill someone it gives me a random amount of Cash Kills and Xp.
Here is the script:
local knife = script.Parent
local handle = knife:WaitForChild("Handle")
local throwRE = knife:WaitForChild("ThrowKnife")
local throwAnim = script:WaitForChild("ThrowAnimation")
local cooldown = 3
local isCooldown = false
throwRE.OnServerEvent:Connect(function(plr, mouseHit)
01 | local character = plr.Character |
03 | local stats = plr:FindFirstChild( "leaderstats" ) |
05 | local kills = stats:FindFirstChild( "Kills" ) |
06 | local xP = stats:FindFirstChild( "XP" ) |
07 | local DocDollars = stats:FindFirstChild( "DocDollars" ) |
09 | if not character or not character:FindFirstChild( "Humanoid" ) then return end |
12 | if isCooldown then return end |
16 | character.Humanoid:LoadAnimation(throwAnim):Play() |
22 | local knifeClone = handle:Clone() |
23 | knifeClone.Velocity = mouseHit.LookVector * 600 |
25 | knifeClone.Parent = workspace |
27 | handle.Transparency = 1 |
29 | knifeClone.Throw:Play() |
32 | knifeClone.CFrame = CFrame.new(knifeClone.Position, mouseHit.LookVector * 300 ) |
35 | local bav = Instance.new( "BodyAngularVelocity" ) |
36 | bav.MaxTorque = Vector 3. new( math.huge , math.huge , math.huge ) |
38 | bav.AngularVelocity = knifeClone.CFrame:VectorToWorldSpace(Vector 3. new(- 400 , 0 , 0 )) |
39 | bav.Parent = knifeClone |
42 | game.ReplicatedStorage.ClientKnife:FireAllClients(knifeClone, knife.Parent) |
45 | knifeClone.Touched:Connect( function (touched) |
47 | if touched.Transparency < 1 and not knife.Parent:IsAncestorOf(touched) then |
49 | local humanoid = touched.Parent:FindFirstChild( "Humanoid" ) or touched.Parent.Parent:FindFirstChild( "Humanoid" ) |
55 | xP.Value = xP.Value + 3 |
56 | DocDollars.Value = DocDollars.Value + 50 |
57 | kills.Value = kills.Value + 1 |
60 | knifeClone.Anchored = true |
63 | wait(knifeClone.Hit.TimeLength) |
71 | handle.Transparency = 0 |
end)