I have a LocalScript that essentially checks an Attribute in a Player to see if it’s true or false, and based on that will decide whether or not to create/enable a Proximity Prompt on eligible players in the game. My issue is that I think this may be a cause of lag when large amounts of players are in my game. How can I rewrite this so that it retains the same function but doesn’t create the insane amount of lag? Thanks!
Here’s my code:
if Prompts then
RunService:BindToRenderStep("TippingPrompts", 0, function()
local CurrentPlayers = Players:GetChildren()
for _, Player in ipairs(CurrentPlayers) do
if Player:GetRankInGroup(GroupID) >= StaffRank and Player ~= LocalPlayer then
local Character = Player.Character
if Character ~= nil then
local ProximityPrompt = Character.HumanoidRootPart:FindFirstChild("TippingPrompt")
if ProximityPrompt then
if Player:GetAttribute("TipsEnabled") then
ProximityPrompt.Enabled = true
else
ProximityPrompt.Enabled = false
end
else
ProximityPrompt = Instance.new("ProximityPrompt")
ProximityPrompt.Name = "TippingPrompt"
ProximityPrompt.RequiresLineOfSight = false
ProximityPrompt.ObjectText = "Tip"
ProximityPrompt.ActionText = Player.Name
ProximityPrompt.MaxActivationDistance = 10
ProximityPrompt.Parent = Character.HumanoidRootPart
ProximityPrompt.Triggered:Connect(function()
if Hub.Visible == false and Prompt.Visible == false then
openPrompt(Player.UserId)
end
end)
if Player:GetAttribute("TipsEnabled") then
ProximityPrompt.Enabled = true
else
ProximityPrompt.Enabled = false
end
end
end
end
end
end)
end
you can maybe offload it to the client since you say it is laggy when there are large amounts of player . The client and tell the server that the player’s rank in the group js high enough . The server would receive the message and verify
To be honest with you, I don’t get why Renderstep was used either. This is a script that was purchased from another scripter by my client and recently the game has been dealing with a lot of lag so I figured this was a possible cause. I was just wondering how I could rewrite this so that there wouldn’t be so much unnecessary checking but still gets the job done. Would you have any ideas by any chance?
This was my initial thought, but when I tried this it simply broke the entire system. No errors in the output, it just simply wouldn’t create the ProximityPrompts. I tried moving things around and doing some reordering to no avail. When I tried adding print statements, nothing would print either. Would you have any suggestions on how to incorporate this without it breaking? Thanks!