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

My value will continue to go down! Help please?

Asked by
Sketchi 18
5 years ago
Edited 5 years ago

I have a system that let's you pick up a part and gives you a folder with the value of the item inside, I try to make a button to delete a specific number of the item (the intValue)... let's say 10, it will delete 10 until I reach the negatives how would I go about making it only take 10 from... let's say if the int value is 50? I also try to give the player money for the amount but it just gives them like 20,000 money when I try to give them only 100. I tried this:

local ITEM = game.ReplicatedStorage.Folder:WaitForChild("Event")
ITEM.OnServerEvent:Connect(function(player)
----
local stats = player:WaitForChild("leaderstats")
local money = stats:FindFirstChild("Money")
---
if player.Inventory:FindFirstChild("example") then

if player.Inventory.example.Value >= 10 then
player.Inventory.example.Value = player.Inventory.example.Value - 10 --- value=value-10
  money.Value = money.Value +100
end
end
end)

What am I doing wrong? Also this is in a server script, I am using an event to trigger it from a local script, os it fine to put this in a server script? Or a local script?

Thanks!

0
You should be doing this in a server script, that's where all player stat changing should be handled, but you also have to add checks to see if the player has earnt the money (exploiters can fire remote events whenever they want) mattscy 3725 — 5y
0
This code should work I think. Did you put a debounce on the click so that the code does not run twice at once? TiredMelon 405 — 5y
0
The fire event* TiredMelon 405 — 5y
0
I dont understand how to add a debounce to a click script, could anyone share an example? Im stumped. I am also working on an exploit proof system. Sketchi 18 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

debounce

    debounce = true
    local ITEM = game.ReplicatedStorage.Folder:WaitForChild("Event")
    ITEM.OnServerEvent:Connect(function(player)
    ----

    local stats = player:WaitForChild("leaderstats")
    local money = stats:FindFirstChild("Money")
    ---
    if player.Inventory:FindFirstChild("example") then
    if not debounce then return end
    debounce = false

    if player.Inventory.example.Value >= 10 then
    player.Inventory.example.Value = player.Inventory.example.Value - 10 --- value=value-10
      money.Value = money.Value +100
    debounce = true
    end
    end
    end)

lol try this i'm not the best at coding so please don't be mad at me if it doesn't work.

0
Thank you, ill try it and ill tell you if it works, i appreciate the answer either way Sketchi 18 — 5y
0
It works great, the only issue is they can only give the item once and not again, or until they run out of the example. Sketchi 18 — 5y
0
Nvm i messed with it now it works perfect, thank you so much Sketchi 18 — 5y
Ad

Answer this question