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

i keep getting an error with my rebirths script and i dont know why why?

Asked by 3 years ago

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)
0
you missing 1 "end)".... MRWHIT3o01 0 — 3y
0
no i have it cjkizzy286 40 — 3y
0
In general, shorten every line with a variable: local statsValue = player.PlayerGui.ScreenGui.StatsValue local milk = statsValue.milk, etc. Also, is everything inside StatsValue a NumberValue, or what are their types blowup999 659 — 3y

3 answers

Log in to vote
0
Answered by
Syclya 224 Moderation Voter
3 years ago
Edited 3 years ago

All UI-related things should be handled by the client, ex this:

player.PlayerGui.ScreenGui.Frame.Rebirth.MouseButton1Click:Connect(function()
   Rebirth()
end)

Ad
Log in to vote
0
Answered by 3 years ago

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

Log in to vote
-1
Answered by 3 years ago
if Coins.Value >= ammountneededtorebirth.Value

This line makes sure player has the exact amount or more than enough to buy. Hope this helps!

0
ive tried that cjkizzy286 40 — 3y

Answer this question