Adding a snow particle emitter with a touch function freezes/lags models?

Heya! So i have this game, where there are two areas (Outside, Inside), and outside i want there to be snowfall, im using a Part with a particle emitter in it that locks to the camera to simulate snow.

there are two parts near the exit that tells a player script whether they are inside or outside… now this does work, for the most part, but the problem is, some player models either lag or full on freeze when going through the parts, Im not entirely sure why this is the case and ive tried a few things but nothing has seemed to work so far, i also have a fog script (thats seperate from the snow script) that works pretty much the same but puts an atmosphere into lighting, but it doesnt lag at all.
heres an example of the problem

here’s the Script:

local lighting = game:GetService("Lighting")
task.wait(2)
local outside = workspace["Fog changes"]["Fog change outside"]
local inside = workspace["Fog changes"]["Fog change inside"]

local player = game.Players.LocalPlayer


local function snow()
	if player.Character:FindFirstChild("Snow emitta") then
		player.Character["Snow emitta"]:Destroy()
		player.PlayerScripts["locked to cam"]:destroy()
	end
		local snow = game.ReplicatedStorage["Snow emitta"]:Clone()
		snow.Parent = player.Character
		snow["locked to cam"].Parent = player.PlayerScripts
		task.wait(0.3)
		player.PlayerScripts["locked to cam"].Enabled = true
end

local function nosnow()
	if player.Character:FindFirstChild("Snow emitta") then
		player.Character["Snow emitta"]:Destroy()
		player.PlayerScripts["locked to cam"]:destroy()
	end
end

outside.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChildOfClass("Humanoid") then
		snow()
	end
end)

inside.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChildOfClass("Humanoid") then
		nosnow()
	end
end)

and also the locked to camera script if its needed

local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer.Character
local SnowPart = player["Snow emitta"]["Snow thing"]
local Cam = workspace.CurrentCamera
local Offset = Vector3.new(0, 10, 0)

RunService.RenderStepped:Connect(function(dt)
	SnowPart.Position = Cam.CFrame.Position + Offset
end)

assuming "Snow emitta" is a part, you have to turn off the Anchored property in it.

because by looking at your video, i can see that you still have full control over the character BUT it’s locked in place. adding an anchored part to the character model will anchor it in place, preventing movement.

Its not anchored, that was one of the first things i made sure of.

Add a debounce, the result of your lag is probably from the rapid firing of the .Touched Event. To prevent this use a debounce.

1 Like

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