Veriable/math help

Whenever I click it does not add 0.1 to the rebirth value, how do I fix this?

local player = game:GetService("Players")
local rebirth = player.LocalPlayer.OtherStuff.rebirths
local rebirthcost = player.LocalPlayer.OtherStuff.rebirthcost
local cash = player.LocalPlayer.leaderstats.Cash
local wood = player.LocalPlayer.leaderstats.Wood

script.Parent.MouseButton1Click:Connect(function()
	if cash.Value >= rebirthcost.Value then   
		rebirthcost.Value *= 3.75
		rebirth.Value += 0.1
		math.ceil(rebirthcost.Value)
		cash.Value = 0
		wood.Value = 0
		print(rebirth.Value)
	else
		print("not enough money")
	end
end)

perhaps this is a localscript? and the server wont register it

I did make it into a normal script but not ti is saying iindex nil with otherstuff can you help?

You cant make server changes from the client and the server can’t manage UI input.

You need to have your local script detect when a UI button is pressed, fire a remote event to the server then the server does the calculation logic and adds +0.1

that is because u cant use things like .mousebutton1cick on server so u you’d haave to make a remote event and a local script

just to check, I make a function in another script that does what this does and when it is clicked it sends the remote evnet and fires the function from the other scirpt,.

Quick example:

-- Local script

myUIButton.MouseButton1Click:Connect(function() -- user presses button
   myRemoteEvent:Fire() -- fire remote to the server
end)


---------------------------------------------------------

-- Server Script

myRemoteEvent.OnServerEvent:Connect(function(player) -- server detects remote was fired
   -- do logic on the server
end)

it is saying the other stuff is not a valid member of me

Hello, I tried to analyze your issue and found this. I hope I can help you because I am currently a beginner in programming on Roblox.


local player = game:GetService("Players")
local rebirth = player.LocalPlayer.OtherStuff.rebirths
local rebirthcost = player.LocalPlayer.OtherStuff.rebirthcost
local cash = player.LocalPlayer.leaderstats.Cash
local wood = player.LocalPlayer.leaderstats.Wood

script.Parent.MouseButton1Click:Connect(function()
	if cash.Value >= rebirthcost.Value then   
		rebirthcost.Value = rebirthcost.Value * 3.75
		rebirth.Value = rebirth.Value + 0.1
		rebirthcost.Value = math.ceil(rebirthcost.Value)
		cash.Value = 0
		wood.Value = 0
		print(rebirth.Value)
	else
		print("not enough money")
	end
end)

sorry it still does not work, thankyou for tryine though

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.