I have been trying to write a script where if I click a GUI button it gives you + 1 money and it doesn't work. It says it has to be an equal sign. So can someone please tell me how to get it to be a plus sign. button.MouseButton1Click:Connect(function()
player.Character.leaderstats.OoferBucks.Value = 1
end) That is what I have right there if I put a + sign where the equal sign is it says that it is wrong. If someone could tell me what to do that would be awesome. Thanks!
Your current line
player.Character.leaderstats.OoferBucks.Value = 1
The problem with this, is that it will constantly set the value to 1, instead of adding.
First of all, I'll add a line that holds the OoferBucks Instance, to make the next line shorter and easier to understand:
local OoferBucks = player.Character.leaderstats.OoferBucks
Next, the correct way to add 1 to a value, is to set its value to itself + 1. Like this:
OoferBucks.Value = OoferBucks.Value + 1
So the final script would be:
local OoferBucks = player.Character.leaderstats.OoferBucks OoferBucks.Value = OoferBucks.Value + 1
Hope this helps!
You would start of by making leaderstats
-- Normal script in ServerScriptService game.Players.PlayerAdded:Connect(function(Player) local Stats = Instance.new("Folder", Player) Stats.Name = "leaderstats" -- The name most be leaderstats, or this would not work! local Money = Instance.new("IntValue", Stats) Money.Name = "Money" Money.Value = 0 end)
So now, you would need another script inside the gui button, remember it should be a Local Script.
local Player = game.Players.LocalPlayer local Stats = Player:WaitForChild("leaderstats") local Money = Stats:WaitForChild("Money") local UI = script.Parent -- UI is the ScreenGui local Button = UI.Button local Debounce = false -- this prevent from spamming the button! Button.MouseButton1Click:Connect(function() if Debounce == false then Debounce = true Money.Value = Money.Value + 1 wait(2) -- this is the amount of secounds you should wait before getting more money! Debounce = false end end)
Hope this helped you out, this is not FE Enabled!