Hey.
I need help with my Remote Event reading a Local Script.
Local Script
local player = game.Players.LocalPlayer
local value = 123 -- These two lines of code are only here to help you guys understand the code
local RemoteEvent = game.Workspace.Main.BuyUpgrade
RemoteEvent:FireServer(player,value)
Script in ServerScriptService
local RemoteEvent = game.Workspace.Main:WaitForChild("BuyUpgrade")
RemoteEvent.OnServerEvent:Connect(function(player, value)
print("Started Remote Event", player.Name, player.leaderstats.Name) -- It does work
player.leaderstats.Money.Value = player.leaderstats.Money.Value - value -- but I cant get it to change any values.
print(player.leaderstats.Money.Value, value)
end)
Here is the error I get:
ServerScriptService.BuyUpgrade:6: attempt to perform arithmetic (sub) on number and Instance
You don’t need to fire the first argument in local script.
local player = game.Players.LocalPlayer
local value = 123 -- These two lines of code are only here to help you guys understand the code
local RemoteEvent = game.Workspace.Main.BuyUpgrade
RemoteEvent:FireServer(value,price must be a number or value)
local RemoteEvent = game.Workspace.Main:WaitForChild("BuyUpgrade")
RemoteEvent.OnServerEvent:Connect(function(player, value, price)
print("Started Remote Event", player.Name, player.leaderstats.Name) -- It does work
if player.leaderstats.Money.Value >= price then -- but I cant get it to change any values.
player.leaderstats.Money.Value = player.leaderstats.Money.Value - price
print(player.leaderstats.Money.Value, value)
end
end)
Added if statement
Ok I got it to work. Thanks for the suggestion, somehow an if statement fixed it.
if player.leaderstats:FindFirstChild("Money") ~= nil then
player.leaderstats.Money.Value = player.leaderstats.Money.Value - value
end
Thanks
Althought yours is slightly different I will mark it as the solution