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

subtracting intValue on pickup?

Asked by 3 years ago

im trying to make it so if you pick something up it subtracts an intsValue Value by 100 and if you don't have 100 value on your intValue you can't pick it up

1 answer

Log in to vote
0
Answered by 3 years ago

You would have to do the picking up part but here's a solution.

When a player has enough points he can pick it up and it subtracts it but the part will delete so you have to figure out that for yourself.

Leaderstats Script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local IntValStat = Instance.new("IntValue", leaderstats)
    IntValStat.Name = "IntValStat"
    IntValStat.Value = 500 -- The value of your intstat by default
end)

Script in part:

-- Script in the part
-- Normal Script


local clickdetector = script.Parent.ClickDetector
local part = script.Parent

clickdetector.MouseClick:Connect(function(player)

    if player.leaderstats.IntValStat.Value >= 100 then -- if the player has 100 or more "points" then he gets to pick it up
        print("Player has enough money!")

        player.leaderstats.IntValStat.Value = player.leaderstats.IntValStat.Value - 100 -- Subtracts the points
        part:Destroy()
    else
        print("Player does not have enough money!")
    end

end)

0
It is better for game performance to parent the Folder and IntValue on a seperate line. You should not parent it on the same line that you create it on. TheFireBurnsBright 0 — 3y
Ad

Answer this question