I’m using a script which checks every second in a while loop a value to see if its greater than 30. I have to use a server script but for some reason the value isn’t updating in the script. Here’s the code that is inside the while loop:
if player.Character.FlightSystemValues.FPM.Value <= 30 then
profile.Data.Achievements.FPM = true
end
Does anyone know how to make it so that the value still updates on the serverscript?
For starters, the condition if newValue <= 30 then
checks if the value is less than or equal to 30, not greater than, which would use the >
symbol. Secondly, it’s better for performance to avoid using while
loops and instead utilize events such as GetPropertyChangedSignal
for property changes. Here’s an improved approach:
player.Character.FlightSystemValues.FPM:GetPropertyChangedSignal("Value"):Connect(function(newValue)
if newValue > 30 then
profile.Data.Achievements.FPM = true
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Wait for character to be added and values to be ready
player.CharacterAdded:Connect(function(character)
local flightSystemValues = character:WaitForChild("FlightSystemValues")
local fpmValue = flightSystemValues:WaitForChild("FPM")
local profile = player:WaitForChild("Profile") -- Adjust based on your actual profile retrieval method
-- Connect to the .Changed event of the FPM value
fpmValue.Changed:Connect(function(newValue)
if newValue <= 30 then
-- Assuming profile.Data.Achievements.FPM is accessible and modifiable
profile.Data.Achievements.FPM = true
end
end)
end)
end)
1 Like