Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so when a player dies then they lose 100 cash?

Asked by 2 years ago

Keep the script th same but make it so when a player dies then they will lose 100 cash.

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)

        c:WaitForChild("Humanoid").Died:Connect(function()

            local bag = script.Moneybag:Clone()

            local cf = c.HumanoidRootPart.CFrame - Vector3.new(0, (c.HumanoidRootPart.Size.Y * 1.5) - (bag.Size.Y / 2), 0)

            bag.CFrame = cf

            local proximityPrompt = Instance.new("ProximityPrompt", bag)
            proximityPrompt.ActionText = "Hold E to pickup 100 cash!"
            proximityPrompt.HoldDuration = 1

            proximityPrompt.Triggered:Connect(function(playerTriggered)

                playerTriggered.leaderstats.Cash.Value += 100

                bag:Destroy()
            end)

            bag.Parent = workspace
        end)
    end)
end)

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

try this:

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)

        c:WaitForChild("Humanoid").Died:Connect(function()

            local bag = script.Moneybag:Clone()

            local cf = c.HumanoidRootPart.CFrame - Vector3.new(0, (c.HumanoidRootPart.Size.Y * 1.5) - (bag.Size.Y / 2), 0)

            bag.CFrame = cf

            local proximityPrompt = Instance.new("ProximityPrompt", bag)
            proximityPrompt.ActionText = "Hold E to pickup 100 cash!"
            proximityPrompt.HoldDuration = 1

            proximityPrompt.Triggered:Connect(function(playerTriggered)

                playerTriggered.leaderstats.Cash.Value = playerTriggered.leaderstats.Cash.Value - 100

                bag:Destroy()
            end)

            bag.Parent = workspace
        end)
    end)
end)
Ad
Log in to vote
0
Answered by 2 years ago

Change playerTriggered.leaderstats.Cash.Value += 100 to playerTriggered.leaderstats.Cash.Value = playerTriggered.leaderstats.Cash.Value - 100

Answer this question