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

Why is my script removing ten when i told it to only remove five, how is that even possible?

Asked by 4 years ago
Edited 4 years ago

server script there is nothing that is changing the value xept this i have checked many times my script:

local tool = game.ReplicatedStorage.Tools.Sign
local remote = game.ReplicatedStorage.Tools.Buy_Sign
print("runned")
--------------------------------------------------
remote.OnServerEvent:Connect(function(player,Vorth)
    ------------------------------------------------
    local coins = player:WaitForChild("leaderstats").Coins
    -------------------------------------------------
    --remove coins
    coins.Value = coins.Value - 5

    --Move tool to the player and set id.
    tool.Parent = player.Backpack
end
0
Your event can be firing twicee Fad99 286 — 4y
0
It is using a text button Freddan2006YT 88 — 4y
0
print (coins.Value - 5) asdfghjk9019 225 — 4y
0
yea it must be running twice cheetahjad -4 — 4y
View all comments (4 more)
0
It print's -5 Freddan2006YT 88 — 4y
0
It is Not running twice i know that Freddan2006YT 88 — 4y
0
whats the result of printing asdfghjk9019 225 — 4y
0
Thankyou everyone for trying to help i really apreciate it! Freddan2006YT 88 — 4y

2 answers

Log in to vote
2
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Hello, Freddan2006YT!

I think the only thing missing on your script is a debounce variable, it prevents the code from running twice on a small time period

I've added it to your script

local tool = game.ReplicatedStorage.Tools.Sign
local remote = game.ReplicatedStorage.Tools.Buy_Sign

local deb = false --Variable used for debounce

print("runned")
--------------------------------------------------
remote.OnServerEvent:Connect(function(player,Vorth)
   if(deb == false)then -- Lets code execute if variable "deb" is false
      deb = true -- Prevents code from running again
      ------------------------------------------------
      local coins = player:WaitForChild("leaderstats").Coins
      -------------------------------------------------
      --remove coins
      coins.Value = coins.Value - 5

      --Move tool to the player and set id.
      tool.Parent = player.Backpack
      wait(0.5)--Wait 0.5 before making code able to run again
      deb = false
    end
end

Edit¹: Also, this prevents hackers/exploiters from flooding their money change(or others)

Edit²: It would be good if you add something to check if player money is less than 5, so the player would not be able to have negative money

If I helped, please upvote and mark answer as accepted

0
It dosen't even remove any coins now or add the item Freddan2006YT 88 — 4y
0
hmmm Freddan2006YT 88 — 4y
0
I really don't know why, do it prints any errors on developer console(F9)? Leamir 3138 — 4y
0
Because deb is nil and will never equal false User#24403 69 — 4y
1
@incapaxx I've just changed it, I hope it works now(thanks for the hint) Leamir 3138 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I have kinda fixed it I'm very confused why I need to do this to make it work someone explain if you know why

local tool = game.ReplicatedStorage.Tools.Sign
local remote = game.ReplicatedStorage.Tools.Buy_Sign

local deb --Variable used for debounce
--------------------------------------------------
remote.OnServerEvent:Connect(function(player)
   if not deb then  -- Lets code execute if variable "deb" is false
      deb = true -- Prevents code from running again
      ------------------------------------------------
      local coins = player:WaitForChild("leaderstats").Coins
      -------------------------------------------------
      --remove coins
      coins.Value = coins.Value - 5
      tool.Parent = player.Backpack
      wait(0.5)--Wait 0.5 before making code able to run again
      deb = false
      coins.Value = coins.Value +5
    end
end)
0
I'm gonna accept you becuse tried to help me :) Freddan2006YT 88 — 4y
0
You need to do because sometimes roblox glitches and fires a client/server 2x Leamir 3138 — 4y

Answer this question