everytime my character rebirths i get the error: 09:02:36.533 - ServerScriptService.Main:37: attempt to index number with 'Value' the code is :
game.ReplicatedStorage.Milktest.OnServerEvent:Connect(function(player) local milk = player.PlayerGui.ScreenGui.StatsValue.milk local Coins = player.PlayerGui.ScreenGui.StatsValue.Coins local Rebirths = player.PlayerGui.ScreenGui.StatsValue.Rebirths local rebirthmultiplyer = player.PlayerGui.ScreenGui.StatsValue.Rebirthmultiplier local ammountneededtorebirth = player.PlayerGui.ScreenGui.StatsValue.AmmountneededtoRebirth local ammountperrebirth = player.PlayerGui.ScreenGui.StatsValue.Ammountperrebirth local ammountperrebirth = ammountneededtorebirth.Value * Rebirths.Value milk.Value = milk.Value + 1 local function Rebirth() if Coins.Value > ammountneededtorebirth.Value then --this is whats wronh Rebirths.Value = Rebirths.Value + 1 rebirthmultiplyer.Value = rebirthmultiplyer.Value + 0.1 ammountneededtorebirth = ammountperrebirth Coins.Value = 0 end end player.PlayerGui.ScreenGui.Frame.Rebirth.MouseButton1Click:Connect(function() Rebirth() end)
All UI-related things should be handled by the client, ex this:
player.PlayerGui.ScreenGui.Frame.Rebirth.MouseButton1Click:Connect(function() Rebirth() end)
Two things that I see as possibilities. This is without knowing everything about the values and gui. You define amountperrebirth as a value in the gui and then immediately redefine it as a value multiplied by two values which might not be anything but it does make the first definition useless. Next, if "rebirthmultiplyer" is an intvalue then it wont add a value less than 1. When referencing the gui from the server, you should always define it like this
local amountperrebirth = player.PlayerGui:findFirstChild("Ammountperrebirth",true) If amountperrebirth then Code here end
if Coins.Value >= ammountneededtorebirth.Value
This line makes sure player has the exact amount or more than enough to buy. Hope this helps!