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
COMMUNITY QUESTION
subtracting intValue on pickup?
1 answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
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.