Im a starter in roblox scripting and i want to know what and where i need to add to makes this values really changes

stats script:

game.Players.PlayerAdded:Connect(function(player)
	local stat = Instance.new("Folder", player)
	stat.Name = "stats"
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = player.stats
	
	local Multiplayer = Instance.new("IntValue")
	Multiplayer.Name = "Multi"
	Multiplayer.Value = 1
	Multiplayer.Parent = player.stats
	
	while true do
		task.wait(1)
		money.Value += 1 * Multiplayer.Value
	end
	
end)

upgrade button script:

local Player = game.Players.LocalPlayer
local Money = Player.stats:FindFirstChild("Money")
local Multi = Player.stats:FindFirstChild("Multi")

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Event = Remotes:WaitForChild("DoubleMoneyGainEvent")

local screenGUI = script.Parent
local GuiHolder = screenGUI.GuiHolder
local UpgradesHolder = GuiHolder.UpgradesHolder
local StatsHolder = GuiHolder.StatsHolder

local DoubleMoneyGainButton = UpgradesHolder.DoubleMoney.UpgradeButton

local function DoubleMoneyGain()
	local NumberOfUpgrades = DoubleMoneyGainButton.NumberOfUpgrades
	if NumberOfUpgrades.Value == 0 and Money.Value >= 5 then
		Money.Value -= 5
		Multi.Value *= 2
		NumberOfUpgrades.Value += 1
		Event:FireServer()
	end
end

DoubleMoneyGainButton.MouseButton1Click:Connect(DoubleMoneyGain)

3 Likes

So whats working and whats not? (e.g is the money value increasing in leaderstats) because I cant really tell whats what like is “holder” supposed to be a text label or frame?

1 Like

everything works just when im cluck upgrade button my cash get - 5 but after a second it goes to value it was and didn’t get a multiplayer

1 Like

then its probably a problem with replicated storage?
im also new so im not 100% sure

Idk the reason for using :WaitForChild instead of :GetService because I’ve always used :GetService(“ReplicatedService”)
same thing for your remotes and events, I would just index them normally

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Event = Remotes.DoubleMoneyGainEvent
1 Like

nah there is something else its still doesnt work

The player isn’t earning any money because 1x1 = 1

no he earns money and problem absolutely not in this

whats this for? is there another server script because i dont see this event being recienved on your first script

this is RemoteEvent From ReplicatedStorage

I never noticed you using += 1 then

yeah you fired the remote event from client but the server should do something once it recieved it

so what i need to do???

we can just code the logistics in the server script so change this to

local function DoubleMoneyGain()
	local NumberOfUpgrades = DoubleMoneyGainButton.NumberOfUpgrades
		NumberOfUpgrades.Value += 1
		Event:FireServer()
	end
end

then add the part we removed to the server script (add this to the top of the server script)

Event.OnServerEvent:Connect(function(player) 
	Money.Value -= 5
	Multi.Value *= 2
end)

Nah it giving me error: OnServerEvent can only be used on the server - Client - LocalScript:24

ok i almost got it im switched script from local to server
im just need to find where do i put MouseButton1Click and RemoteEvent

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local RemoteEvent = Remotes:WaitForChild("DoubleMoneyGainEvent")

local screenGUI = script.Parent
local GuiHolder = screenGUI.GuiHolder
local UpgradesHolder = GuiHolder.UpgradesHolder
local StatsHolder = GuiHolder.StatsHolder
local DoubleMoneyGainButton = UpgradesHolder.DoubleMoney.UpgradeButton

--DoubleMoneyGainButton.MouseButton1Click:Connect(function(player)
	local Money = player.stats:FindFirstChild("Money")
	local Multi = player.stats:FindFirstChild("Multi")

	local NumberOfUpgrades = DoubleMoneyGainButton.NumberOfUpgrades
	if NumberOfUpgrades.Value == 0 and Money.Value >= 5 then
		Money.Value -= 5
		Multi.Value *= 2
		NumberOfUpgrades.Value += 1
	end
end)

--where do u need to put those?
--RemoteEvent:FireServer()
--DoubleMoneyGainButton.MouseButton1Click:Connect(function(player)
	end
end)

nooooooooooooo
remote event is used to communicate between server and client scripts
idk why dev forum send the notification so late
I dont think you can access guis through server scripts so your new script wont work

you have to put this inside of the server script!!! thats what i said!!

this is the only part that needs to be inside of the server script

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