I have a leveling up system that plays a cool little animation when the player levels up, and it works nicely, however the problems start when it uses a remote event to reward the player. Here is my script:
local player = game.Players.LocalPlayer
local title = script.Parent.LevelTitle
local num = script.Parent.LevelNum
local reward1 = script.Parent.CashRew
local level = game.Players.LocalPlayer.LevelingSystem.Level
local event = game.ReplicatedStorage.RewardRE.LevelUpReward
level:GetPropertyChangedSignal("Value"):Connect(function()
local rew = math.random(325,550)
num.Text = level.Value - 1
title.Visible = true
title:TweenPosition(UDim2.new(0.501, 0,0.313, 0), "Out", "Quad", 0.5)
wait(1)
num:TweenPosition(UDim2.new(0.5, 0,0.406, 0), "Out", "Quad", 0.5)
wait(1)
num.Text = num.Text + 1
wait(1)
reward1.Text = "+ $"..rew
reward1:TweenPosition(UDim2.new(0.5, 0,0.486, 0), "Out", "Quad", 0.5)
wait(2)
reward1:TweenPosition(UDim2.new(0.5, 0,-1.486, 0), "Out", "Quad", 0.5)
title:TweenPosition(UDim2.new(0.501, 0,1.313, 0), "Out", "Quad", 0.5)
num:TweenPosition(UDim2.new(0.5, 0,1.406, 0), "Out", "Quad", 0.5)
print(rew)
event:FireServer(player, rew)
end)
Here is the server script:
local event = game.ReplicatedStorage.RewardRE.LevelUpReward
event.OnServerEvent:Connect(function(player, rew)
local player = game.Players:FindFirstChild(player.Name)
print(rew)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + rew
print("Awarded "..tostring(player.Name).." $ "..rew)
end)
When I ask to print what "rew" is (rew is the math.random value that is supposed to be the players reward) it says that rew is the players name, and then errors because you cannot perform arithmetic with an Instance. Please help, I don't know what is wrong.

1 comment
thank you very much