I am trying to make a rebirth GUI system where the user inputs the amount of rebirths they want and it will send the inputted amount through a remote event to serverscriptservice where it adds the inputted amount of rebirths. However I get this error -
ServerScriptService.rebirth:4: attempt to perform arithmetic (mul) on number and nil
Layout -
https://i.ibb.co/b2PcvYG/Capture.png
Local Rebirth Script -
script.Parent.MouseButton1Click:connect(function() local amount = script.Parent.Parent.Parent.TextBox.Text amount = tonumber(amount) print(amount) game.ReplicatedStorage.rebirth:FireServer(amount) end)
ServerScriptService rebirth script -
game.Players.PlayerAdded:Connect(function(player, amount) game.ReplicatedStorage.rebirth.OnServerEvent:Connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats.Money.Value >= 1000000 * amount then leaderstats.Rebirths.Value = leaderstats.Rebirths.Value + amount leaderstats.Money.Value = 0 player.Character.Head:Destroy() else player.PlayerGui.Gui.badframe.Visible = true wait(1) player.PlayerGui.Gui.badframe.Visible = false end end) end)
Firstly, game.Players.PlayerAdded only accepts 1 parameter, which is the new player. Secondly, you can't manipulate the GUI on the server, you have to do it on the client. Thirdly, you can send tuple arguments with the FireServer()
function, however, the first parameter has to be the player. So what I suggest you do is on the client, you change the playerGui that way, and on the server, you change the leaderstats only.
Local Script
local player = game.Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") script.Parent.MouseButton1Click:Connect(function() --connect is deprecated. Use Connect. local amount = script.Parent.Parent.Parent.TextBox.Text amount = tonumber(amount) --This is VERY vulnerable, always change the values on the server. Exploiters can exploit it. if player.leaderstats.Money.Value >= 1000000 * amount then --This is only reading the value, which is fine on the client. game.ReplicatedStorage.rebirth:FireServer(amount) else player.PlayerGui.Gui.badframe.Visible = true wait(1) player.PlayerGui.Gui.badframe.Visible = false end end)
Server Script
game.ReplicatedStorage.rebirth.OnServerEvent:Connect(function(player, amount) local leaderstats = player:WaitForChild("leaderstats") --This is a better alternative since you need it. leaderstats.Rebirths.Value = leaderstats.Rebirths.Value + amount leaderstats.Money.Value = 0 player.Character.Head:Destroy() end)
(Note on the amount variable. Always change the values on the server. You can use an IntValue and place it ReplicatedStorage. But that's kind of off-topic.)