I’ve made a number variable inside a scope so the variable is created multiple times but somehow it keeps changing after the second time the variable was made. The yellow text next to the “-” button displays the number variable. Here is the footage
Here is the script:
local module = {}
function module:RequestGemConvert()
if script.Parent.GemConverter.Open.Value == false then
script.Parent.GemConverter.Open.Value = true
module:CloseAllGui("GemConverter")
local Coins = 0
local MaximumCoins = game.ReplicatedStorage.ConvertGems:InvokeServer(0,false) -- so we would only invoke it once
script.Parent.GemConverter.Background:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quint",0.5,true)
script.Parent.GemConverter.Background.Add.MouseButton1Click:Connect(function()
Coins = Coins + 1
end)
script.Parent.GemConverter.Background.Subtract.MouseButton1Click:Connect(function()
Coins = Coins - 1
end)
script.Parent.GemConverter.Background.Max.MouseButton1Click:Connect(function()
Coins = MaximumCoins
end)
script.Parent.GemConverter.Background.Min.MouseButton1Click:Connect(function()
Coins = 0
end)
script.Parent.GemConverter.Background.Convert.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ConvertGems:InvokeServer(Coins,true)
script.Parent.GemConverter.Background:TweenPosition(UDim2.new(0.5,0,1.5,0),"In","Quint",0.5,true)
module:SendNotification("Awesome!","Successfully converted your coins to Gems!")
script.Parent.GemConverter.Open.Value = false
end)
script.Parent.GemConverter.Background.Exit.MouseButton1Click:Connect(function()
script.Parent.GemConverter.Background:TweenPosition(UDim2.new(0.5,0,1.5,0),"In","Quint",0.5,true)
script.Parent.GemConverter.Open.Value = false
Coins = 0
end)
while wait() do
script.Parent.GemConverter.Background.Coins.TextLabel.Text = module:RequestPlaceValue(Coins)
script.Parent.GemConverter.Background.Gems.TextLabel.Text = module:RequestPlaceValue(math.floor(Coins / 5))
if Coins == game.Players.LocalPlayer:WaitForChild("Leaderstats").Coins.Value then
script.Parent.GemConverter.Background.Add.Visible = false
script.Parent.GemConverter.Background.Subtract.Visible = true
elseif Coins == 0 then
script.Parent.GemConverter.Background.Subtract.Visible = false
script.Parent.GemConverter.Background.Add.Visible = true
else
script.Parent.GemConverter.Background.Add.Visible = true
script.Parent.GemConverter.Background.Subtract.Visible = true
end
end
else
script.Parent.GemConverter.Background:TweenPosition(UDim2.new(0.5,0,1.5,0),"In","Quint",0.5,true)
script.Parent.GemConverter.Open.Value = false
end
return module
Here is the server script:
game.ReplicatedStorage.ConvertGems.OnServerInvoke = function(Player,Coins,Convert)
if Convert then
Player:WaitForChild("Leaderstats").Gems.Value = Player:WaitForChild("Leaderstats").Gems.Value + math.floor(Coins / 5)
Player:WaitForChild("Leaderstats").Coins.Value = Player:WaitForChild("Leaderstats").Coins.Value - Coins
else
return Player:WaitForChild("Leaderstats").Coins.Value
end
end
Also, the RequestGemConvert function is fired when the player’s humanoidrootpart is near to the object I set it