Hello,
I am making a system that gives the player money but the output says:
attempt to perform arithmetic (add) on number and Instance
I am using a local script in StarterGui and a server script in ServerScriptService.
Local script
print("Hello world")
local secLabel = script.Parent:WaitForChild("Sec")
local minLabel = script.Parent:WaitForChild("Min")
local seconds = 1
local minutes = 0
local on = false
local wasOn = false
local earn = 5
local earnings = 0
local moneyFrame = script.Parent.Parent:WaitForChild("Earnings")
local player = game.Players.LocalPlayer
local part = workspace.Pizza:WaitForChild("CustomerChoose")
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
--local part = game.Workspace.Pizza.Part
local distance = (character.HumanoidRootPart.Position - part.Position).magnitude
local maxD = 10
local function stopTimer()
seconds = 1
minutes = 0
secLabel.Parent.Visible = false
moneyFrame.Visible = false
game.ReplicatedStorage.GiveMoney:FireServer(player, earnings)
earnings = 0
end
local function timerForPizza()
repeat
seconds += 1
secLabel.Parent.Visible = true
moneyFrame.Visible = true
if seconds >= 60 then
minutes += 1
seconds = 0
earnings += earn
end
secLabel.Text = tostring(seconds)
minLabel.Text = tostring(minutes)
--player.Jobs.Earn.Value += earn--Change this to the player leader stats
moneyFrame.earn.Text = tostring(earnings)
wait(0.5)
until on == false
end
while wait(1) do
if (character.HumanoidRootPart.Position - part.Position).magnitude < maxD then
timerForPizza()
print("Yay")
if wasOn then
seconds = 1
minutes = 0
wasOn = false
secLabel.Parent.Visible = true
end
else
print("No")
stopTimer()
wasOn = true
game.ReplicatedStorage.GiveMoney:FireServer(player)
end
end
--script.Parent.TextButton.MouseButton1Click:Connect(function()
--on = true
--timerForPizza()
--end)
Here is the line the line that fires the event:
game.ReplicatedStorage.GiveMoney:FireServer(player, earnings)
And here is the server script:
local player = game.Players.LocalPlayer
game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player, earnings)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + earnings
end)