Problem enabling particle emitter

I’m making a simple shift to sprint script, but this one has a key feature: running lines (particle emitter).

local InputService = game:GetService("UserInputService")
local RS = game.ReplicatedStorage
local Player = game.Players.LocalPlayer

wait()

function findFirstChild(parent, child, returnf)
	local trueornot = parent:FindFirstChild(child)
	if parent~=nil then
		return trueornot
	end
end

function findFirstChildOfClass(parent, child, returnf)
	local trueornot = parent:FindFirstChildOfClass(child)
	if parent~=nil then
		return trueornot
	end
end


local d = false

InputService.InputBegan:Connect(function(Input, IsTyping)
	--local Character = Player:WaitForChild("Character")
	if IsTyping==false then
		if Input.KeyCode == Enum.KeyCode.LeftShift then
			
			if d == false then
				d = true
				print("Inputbegan, not typing" .. " " .. Input.KeyCode.Name)
				--local Humanoid = Character

				local plr = game.Players.LocalPlayer
				
				local chr = plr.Character
			
				local hum = findFirstChild(chr, "Humanoid")
				local hrp = findFirstChild(chr, "HumanoidRootPart")
				local pe = findFirstChild(RS, "RunningLines")
				if hum ~=nil and pe~=nil and hrp then
					local peclone = pe:Clone()
					peclone.Parent = hrp
					print(hum)
					hum.WalkSpeed = hum.WalkSpeed + 15
					
					--[[if GetState == Enum.HumanoidStateType.Running and hum.MoveDirection.Magnitude ~=0 then
						peclone.Enabled = true
					end
					]]
					hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
						print("ohhh")
						if hum:GetState() == Enum.HumanoidStateType.Running and hum.MoveDirection.Magnitude~=0 then
							print("runnnnnnnnnnnn")
							
							peclone.Enabled = true
							
							print(peclone.Enabled)
						end
					end)
					
				end
			end
			
		end
	end
	
	InputService.InputEnded:Connect(function(Input, IsTyping)
		--local Character = Player:WaitForChild("Character")
		if IsTyping==false then
			if Input.KeyCode == Enum.KeyCode.LeftShift then
				if d == true then
					d=false
					
					local plr = game.Players.LocalPlayer

					local chr = plr.Character

					local hum = findFirstChild(chr, "Humanoid")
					local hrp = findFirstChild(chr, "HumanoidRootPart")
					
					if hum ~=nil and hrp then
						
						local pee = findFirstChildOfClass(hrp, "ParticleEmitter")
						
						print(hum)
						hum.WalkSpeed = hum.WalkSpeed - 15
						d = false
						
						if pee ~= nil and pee.Name == "RunningLines" then
							
							pee:Destroy()
							
						end
						
					end
				end
			end
		end
	end)
	
end)

Everything works fine, except for that stupid line peclone.Enabled = true
it was working before, but it would stay enabled if I held shift after I stopped. I tried hum:GetState() and hum.StateChanged:Connect(), but they were immediately ignored by the script. But when I tried GetPropertyChangedSignal(), everything within it worked, except for the line that enables the particle emitter. The print(peclone.Enabled) also returns true, but the particle simply refuses to load or smth.

update: It also doesn’t work in the normal player launcher; therefore it isn’t a studio problem

this line works fine, but as I said, I want the particle to be enabled only when the player is running

so disabling to enable later doesn’t work visually, the solution was to just use debris service and check for the existance of the particle to know when to clone or not

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