So I have this wage system for my game, which needs to be updated every two seconds so that it can display on everyone’s screen how much they will get paid / minute. Kinda like on Generic Roleplay Gaem. I got the information to come in threw events on the client side into the server but it isn’t updating the numbers, although there is no error, I even used print and it is making it threw. It only updates once, and that is when the server starts. Also for those wondering I am using a NumberValue in ServerScriptService.
Here is the code, I honestly have no clue why it is doing this so if you know please help. Local:
local event = game.ReplicatedStorage:WaitForChild("WageChange")
local parent = script.Parent.Parent.Parent.Parent.Parent.Parent
local wage = script.Parent.Value
repeat
wait(2)
if parent.Team.Name == "Mayor" then
event:FireServer(wage)
end
until false
nah remote events are the use case for this but u shouldnt be loop firing a remote event u should be using connections to see when team or wage is changed. you should also have the server do some checks, since an exploiter can manipulate the remote events arguments to whatever they want they could easily set the wage to an extreme value like 999999999999999999
Well if the mayor can set the wages at their own free will then you probably should clamp the value on the server so that it cannot go above or below a certan amount. (e.g exploiters setting the wage to -9999 and making everyone poor or setting wage to 9999 and making everyone rich)
I am still getting the problem though of when I click to change it everything will go threw but the number on the server side wont change. Any ideas why?
Anyway here is working code w/ some basic checks added
local script
local event = game.ReplicatedStorage:WaitForChild("WageChange")
local player = game.Players.LocalPlayer
local wage = script.Parent
wage.Changed:Connect(function()
if player.Team.Name == "Mayor" then
event:FireServer(wage.Value)
end
end)
script
local remoteevent = game.ReplicatedStorage.WageChange
remoteevent.OnServerEvent:Connect(function(plr, wage)
if plr.Team.Name == "Mayor" then
script.Parent.Value = math.clamp(wage,0,50)
end
end)