Hello Viewers, I'm trying to create a game where after a second gravity goes down by 1, with this I also created values to try and show each player's gravity, however upon testing my script and spending hours trying to fix it, nothing worked, sorry if I don't provide enough information but any help is appreciated.

Thanks for your help!

Script: (Local) game.StarterPlayer.StarterPlayerScripts

game.Workspace.Gravity = 500
local leaderstats = game.ReplicatedStorage.leaderstats
local plr = game.Players.LocalPlayer
while wait(1) do
	local gravity = game.Workspace.Gravity
	game.Workspace.Gravity = game.Workspace.Gravity -1
	leaderstats:FireServer(plr, gravity)
end

ServerScriptService

local leaderstats = game.ReplicatedStorage.leaderstats

leaderstats.OnServerEvent:Connect(function(plr, gravity)
	if plr:FindFirstChild("leaderstats") then
		while wait(1) do
			plr.leaderstats.Gravity.Value = gravity
			end
	end
end)

5 comments

0

leaderstats:FireServer(gravity) instead of leaderstats:FireServer(plr, gravity), when you are using :FireServer, it's obvious to a LocalScript that LocalPlayer is the one who's firing the event

0

and in the ServerScriptService script remove line 5 and 7 (the while wait loop), you :FireServer every second, meaning it will update the leaderstats once every second...

0

...if you will add another loop in the server script, it will start a loop every time you :FireServer, so every second it will start a loop which will update leaderstats every second, after 10 seconds that's 10 loops created, after 20 seconds that's 20, in the end there will be ...

0

... so many while wait(1) loops in the server script that it will lag like gta 6 or smth

0

Thanks! It works amazingly now