Fps drops when activating tool after long periods of time

my fps keeps dropping after long periods of time of clicking all i am doing is calling a module and a tool that has a value of the gain you get i call the module and pass through the value and then on the module it passes through to a remote event and then on a server script adds the gain, does anybody know how to fix this its been really bugging me for like 2 days straight.

here is the local script:

here is the module:

here is the server script:

if anybody could help i would appreciate it.

The only thing that I think could possibly cause lag is the fact you’re loading the animation which each click, load the animation outside the function instead and just play it inside the animations.

Also, I highly recommend storing the values for the gain on the server side, as if you do it on the client side, an exploiter could just fire the remote even and gain and infinite amount of “Gain”

oh okay i wasn’t thinking about exploiters too thanks for reminding me.


it still does not work it still drops frame this is a video of me being in the game afk clicking for an hour or 2. i seriously do not know what the problem is, im not doing any loops or anything

Yeah I’m confused as well, since there’s no loops or anything. The only other thing I can think of is that it’s either somewhere else in the game, or it’s just the device you’re running it on.

2 Likes
_G.selecteditem = nil

local plr = game.Players.LocalPlayer

local characterInd = workspace:WaitForChild(plr.Name)

local HumanoidInd = characterInd:WaitForChild("Humanoid")

local WeightIndex = require(game.ReplicatedStorage.Modules.Weight_Index)




local WeightShop_Module = {}
WeightShop_Module.__index = WeightShop_Module
local VpFrameInv = script.Parent.Parent:FindFirstChild("HUD"):FindFirstChild("screen"):WaitForChild("bottom"):FindFirstChild("inventory").ViewportFrame


function WeightShop_Module:Equip(Define, Obj)
	local Humanoid = plr.Character:WaitForChild("Humanoid")
	
	
	
	if plr.Backpack:FindFirstChild(Define) then
		Humanoid:EquipTool(plr.Backpack:FindFirstChild(Define))
		script["Equip sound"]:Play()
		script.Parent.Parent.HUD.screen.bottom.inventory.hover_circle.ImageColor3 = Color3.fromRGB(108, 255, 98)
	end
end


function WeightShop_Module:Unequip(Define, Obj)
	local Humanoid = plr.Character:WaitForChild("Humanoid")
	
	
	if plr.Character:FindFirstChild(Define) then
		Humanoid:UnequipTools(plr.Character:FindFirstChild(Define))
		script["Sword Unequip"]:Play()
		script.Parent.Parent.HUD.screen.bottom.inventory.hover_circle.ImageColor3 = Color3.fromRGB(255, 255, 255)
	end
end

function WeightShop_Module:BackpackEquip(Define,Obj)
	local Name = Define
	local Object = Obj
	
	if plr.Backpack:FindFirstChild(Name) or plr.Character:FindFirstChild(Name) then
		
		
		for i,v in pairs(VpFrameInv:GetChildren()) do
			if v  then
				v:Destroy()
			end
		end
		
		wait(1)
		
		local ClonedObject = Object:Clone()
		ClonedObject.Parent = script.Parent.Parent.HUD.screen.bottom.inventory.ViewportFrame
		print("Done")
		
		
		local camera = Instance.new("Camera")
		camera.Parent = VpFrameInv
		
		VpFrameInv.CurrentCamera = camera
		print("Passed")
		
	
		game:GetService("RunService").RenderStepped:Connect(function()

			pcall(function(a)
					if ClonedObject.Handle then
					ClonedObject.Handle.CFrame = (camera.CFrame  * CFrame.new(0,0,-2)* CFrame.Angles(0,math.rad(time()*30),0))
				else
				end 
				end)
				end)
			
	
		
	end
end



function UpdateOnJoin()
	for i,v in pairs(WeightIndex) do
		if plr.Backpack:FindFirstChild(v.Name) or plr.Character:FindFirstChild(v.Name) then
			WeightShop_Module:BackpackEquip(v.Name, game.ReplicatedStorage.Weights:FindFirstChild(v.Name))
		end
	end
end

task.wait(1.5)
UpdateOnJoin()


function WeightShop_Module.Purchase()
	if selecteditem ~= nil then
		reult = game.ReplicatedStorage.Events.Purchase:InvokeServer(selecteditem.Name)
		if reult == true then
			script.Purchase:Play()
			
			
			local clonedSuccessPrompt = game.ReplicatedStorage.SuccessPrompt:Clone()
			clonedSuccessPrompt.Parent = script.Parent.Parent.HUD
			local Msg = "Successfully Purchased "..selecteditem.Name.."!".."✅"
			
			
			for i = 1,#Msg do
				clonedSuccessPrompt.Text = string.sub(Msg, 1, i)
				wait(0.005)
			end
			
			
			
			script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "Owned"
			for i,v in pairs(WeightIndex) do
				if plr.Backpack:FindFirstChild(v.Name) and v.NextWeight ~= "You have completed the weights" then
					WeightShop_Module:BackpackEquip(v.Name, game.ReplicatedStorage.Weights:FindFirstChild(v.Name))
					script.Parent.Parent.Shop.MainFrame.Frame.ButtonHolder:FindFirstChild(v.NextWeight).LockIcon.Visible = false
					script.Parent.Parent.Shop.MainFrame.Frame.ButtonHolder:FindFirstChild(v.NextWeight).ClickButton.Visible = true
				end
			end
			wait(2)
			clonedSuccessPrompt:Destroy()
		elseif reult == false and not plr.Backpack:FindFirstChild(selecteditem.Name) and not plr.OwnedWeights:FindFirstChild(selecteditem.Name) then
			script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "insufficient Coins!"
			wait(0.5)
			script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "Purchase"
		end
	else
		warn("Error Finding Object")
	end
end


function WeightShop_Module:ShowInfo()
	local Name = self.Name
	local Cost = self.Cost
	local Gain = self.Gain
	local NextWeight = self.NextWeight
	
	
	
	script["RBLX UI Swipe (SFX)"]:Play()
	
	local Object = self.Object.Handle
	
	local ClonedObject = Object:Clone()
	
	for i,E in pairs(WeightIndex) do
		if plr.Backpack:FindFirstChild(E.Name) and E.NextWeight ~= "You have completed the weights" then
			script.Parent.Parent.Shop.MainFrame.Frame.ButtonHolder:FindFirstChild(E.NextWeight).LockIcon.Visible = false
			script.Parent.Parent.Shop.MainFrame.Frame.ButtonHolder:FindFirstChild(E.NextWeight).ClickButton.Visible = true
		else
			
		end
		
	end
	
	
	pcall(function()
		for i,v in pairs(script.Parent.Parent.Shop.MainFrame.Info.ItemViewer:GetChildren()) do
		if v.Name ~= "UICorner" and v ~= nil then
			v:Destroy()

		end
	
	end
	end)
	
	
	
	
	selecteditem = self.temp
	

	
	ClonedObject.Parent = script.Parent.Parent.Shop.MainFrame.Info.ItemViewer
	
	local NewCamera = Instance.new("Camera",script.Parent.Parent.Shop.MainFrame.Info.ItemViewer)
	
	NewCamera.CFrame = CFrame.new(ClonedObject.Position) + Vector3.new(0,0.7,3)
	
	
	script.Parent.Parent.Shop.MainFrame.Info.ItemViewer.CurrentCamera = NewCamera
	
	script.Parent.Parent.Shop.MainFrame.Info.ItemName.Text = Name
	script.Parent.Parent.Shop.MainFrame.Info.Price.Text = "💵"..Cost
	script.Parent.Parent.Shop.MainFrame.Info.Gain.Text = "💪"..Gain
	
	if plr.OwnedWeights:FindFirstChild(self.Name) then
		script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "Owned"
	else
		script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "Purchase"
	end
	
	if plr.CurrentWeight.Value == self.Name then
		script.Parent.Parent.Shop.MainFrame.Info.Buy.Text = "Equipped"
	end
	
	
	
	game:GetService("RunService").RenderStepped:Connect(function()
		
				pcall(function()
			if ClonedObject ~= nil then
				ClonedObject.CFrame = (NewCamera.CFrame  * CFrame.new(0,0,-2.5)* CFrame.Angles(0,math.rad(time()*30),0))
			end
		end)
	end)


end







function WeightShop_Module.CreateTemplates(indexMod)
	local self = setmetatable({}, WeightShop_Module)
	
	self.Name = indexMod.Name
	self.Cost = indexMod.Cost
	self.Gain = indexMod.Gain
	self.Object = indexMod.Object
	self.NextWeight = self.NextWeight
	
	
	local clonedTemplate = script.Template:Clone()
	clonedTemplate.Parent = script.Parent.Parent.Shop.MainFrame.Frame.ButtonHolder
	clonedTemplate.Name = self.Name
	self.temp = clonedTemplate
	
	
	
	local Camera = Instance.new("Camera")
	Camera.Parent = clonedTemplate
	

	
	local clonedObject = self.Object.Handle:Clone()
	clonedObject.Parent = Camera
	
	clonedTemplate.CurrentCamera = Camera
	
	clonedTemplate.Camera.CFrame = CFrame.new(clonedObject.Position) + Vector3.new(0,0,3)
	clonedObject.CFrame = CFrame.lookAt(clonedObject.Position, Camera.CFrame.Position)
	
	
	if plr:WaitForChild("OwnedWeights"):FindFirstChild(self.Name) or self.Name == "Pencil"   then
		clonedTemplate.LockIcon.Visible = false
		clonedTemplate.ClickButton.Visible = true
	else
		clonedTemplate.LockIcon.Visible = true
		clonedTemplate.ClickButton.Visible = false
	end
	
	
	return self
end



i do have a shop and i do have some loops in here but i dont know how this would effect the tool activating though sorry for the massive block of code just thought you could maybe look through it as this also contains equipping the tool and things

Can you paste the tool script?

the module

the local script this is inside each tool

I’m talking about actual text not screenshot. And I only the tool one.


local plr = game.Players.LocalPlayer
local char = workspace:WaitForChild(plr.Name)
local Humanoid = char:WaitForChild("Humanoid")


local Module = require(game.ReplicatedStorage.Modules.WeightHandler)




local item = script.Parent


item.Activated:Connect(function()
	Module.Lift(script.Parent.Name, script.Parent.Gain.Value)
	
end)
local Tool:Tool? = script.Parent
local Player:Player? = Tool.Parent.Parent or script.Parent:FindFirstAncestorOfClass("Player")
local Character = Player.Character
local Humanoid:Humanoid? = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid",95)
local Animator:Animator? = Humanoid:FindFirstChildOfClass("Animator")
local DB = false
local Lift:AnimationTrack? = Animator:LoadAnimation(...) -- change
type Player = Player & {
	LiftSpeed: NumberValue?,
	Strength: NumberValue?
}
Tool.Activated:Connect(function()
	if not DB then
		DB = true
		task.delay(Player.LiftSpeed.Value,function()
			DB = false
		end)
		Player.Strength.Value += Tool.Gain.Value
		script.Pass:Play()
		script["soundname"]:Play()
		Lift:Play()
	end
end)

This is a serverscript.

1 Like

will try this now thank you so much for your help.

1 Like

it still drops but way less it ony drops from 60 to 59.4 now so thank you for the help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.