Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

you missing 1 "end)"....

0

no i have it

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

3 answers

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!

1 comment

0

ive tried that

This discussion is preserved as it was. New answers, comments, and votes are closed.