when i play my game , i noticed this . is this normal ? when i play i feel little lag but not always and my game has 12p maximum , heres my script
local GAMEPASS_1_ID = 125836025
local GAMEPASS_2_ID = 110780130
local GAMEPASS_1_AMOUNT = 14
local GAMEPASS_2_AMOUNT = 18
local GAMEPASS_BOTH_AMOUNT = 25
local NO_GAMEPASS_AMOUNT = 6
local RESET_DISTANCE = 500
local function onCharacterAdded(character)
local UserBody = character
local User = game.Players:GetPlayerFromCharacter(UserBody)
local UserHumanoid = UserBody:WaitForChild("Humanoid")
local Sitting = false
local MetersDriven = Instance.new("NumberValue")
MetersDriven.Name = "MetersDriven"
MetersDriven.Value = 0
MetersDriven.Parent = script
local lastEarnedTime = 0
local userOwnsGamePass1 = false
local userOwnsGamePass2 = false
local function updateUserGamePassOwnership()
local success1, result1 = pcall(function()
userOwnsGamePass1 = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(User.UserId, GAMEPASS_1_ID)
end)
local success2, result2 = pcall(function()
userOwnsGamePass2 = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(User.UserId, GAMEPASS_2_ID)
end)
end
updateUserGamePassOwnership()
UserHumanoid.Seated:Connect(function(IsSeated, Seat)
if IsSeated then
if Seat then
Sitting = true
local debounce = false
while task.wait(0.2) do
if debounce then return end
debounce = true
local UserHumanoidRootPart = UserBody:FindFirstChild("HumanoidRootPart")
if Sitting == true and UserHumanoidRootPart then
local Speed = UserHumanoidRootPart.AssemblyLinearVelocity.Magnitude
MetersDriven.Value = MetersDriven.Value + Speed
if MetersDriven.Value > RESET_DISTANCE then
MetersDriven.Value = 0
local currentTime = os.time()
if currentTime - lastEarnedTime >= 1 then
lastEarnedTime = currentTime
if userOwnsGamePass1 and userOwnsGamePass2 then
User.leaderstats.Money.Value = User.leaderstats.Money.Value + GAMEPASS_BOTH_AMOUNT
elseif userOwnsGamePass1 then
User.leaderstats.Money.Value = User.leaderstats.Money.Value + GAMEPASS_1_AMOUNT
elseif userOwnsGamePass2 then
User.leaderstats.Money.Value = User.leaderstats.Money.Value + GAMEPASS_2_AMOUNT
else
User.leaderstats.Money.Value = User.leaderstats.Money.Value + NO_GAMEPASS_AMOUNT
end
end
end
end
debounce = false
end
end
else
Sitting = false
end
end)
User.CharacterRemoving:Connect(function()
MetersDriven:Destroy()
end)
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, isPurchased)
if gamePassId == GAMEPASS_1_ID or gamePassId == GAMEPASS_2_ID then
updateUserGamePassOwnership()
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
onCharacterAdded(character)
end)
end)
what u guys think? if it bad , what should i change