Ad
Log in to vote
0

Stuck on leaderstats Problem?

Asked by 18 days ago

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)

local character = plr.Character

local stats = plr:FindFirstChild("leaderstats")

local kills = stats:FindFirstChild("Kills")
local xP = stats:FindFirstChild("XP")
local DocDollars = stats:FindFirstChild("DocDollars")

if not character or not character:FindFirstChild("Humanoid") then return end


if isCooldown then return end
isCooldown = true


character.Humanoid:LoadAnimation(throwAnim):Play()


wait(0.4)


local knifeClone = handle:Clone()
knifeClone.Velocity = mouseHit.LookVector * 600

knifeClone.Parent = workspace

handle.Transparency = 1

knifeClone.Throw:Play()


knifeClone.CFrame = CFrame.new(knifeClone.Position, mouseHit.LookVector * 300)


local bav = Instance.new("BodyAngularVelocity")
bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

bav.AngularVelocity = knifeClone.CFrame:VectorToWorldSpace(Vector3.new(-400, 0, 0))
bav.Parent = knifeClone


game.ReplicatedStorage.ClientKnife:FireAllClients(knifeClone, knife.Parent)


knifeClone.Touched:Connect(function(touched)

    if touched.Transparency < 1 and not knife.Parent:IsAncestorOf(touched) then 

        local humanoid = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")

        if humanoid then

            humanoid.Health = 0

            xP.Value = xP.Value + 3
            DocDollars.Value = DocDollars.Value + 50
            kills.Value = kills.Value + 1
        end

        knifeClone.Anchored = true

        knifeClone.Hit:Play()
        wait(knifeClone.Hit.TimeLength)
        knifeClone:Destroy()
    end
end)


wait(cooldown - 0.4)
isCooldown = false
handle.Transparency = 0

end)

0
Thanks for all of you who have the heart to help me :) subblox1234 5 — 18d

Answer this question