My Transparency loop doesnt lower transparency

In this script, I am trying to make it so that when you press “c” the script turns you into a barrel with a poof of smoke, however it doesnt work. When I made the “While ClonedS.Transparency >= 0.1 do” line, the error Players.snipperdiaper.PlayerScripts.LocalScript:12: attempt to compare number <= NumberSequence is all I get, and the smoke doesnt stop. I dont know why its making this problem and i’ve tried changing the signs, making different logic etc. I also checked out the roblox particle documentatin and searched up a few things, but nothing worked…

Heres the script:


local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local smoke = ReplicatedStorage.ParticleSmoke.ParticleEmitter

--Function

local function BarrelShift()
	local ClonedS = smoke:Clone()
	ClonedS.Parent = player.Character:FindFirstChild("HumanoidRootPart")
	wait(1.3)
	while ClonedS.Transparency >= 0.1 do
		ClonedS.Transparency = ClonedS.Transparency - 0.5
		wait(0.5)
	end
	ClonedS:Destroy()
end
--UIS input function
UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		BarrelShift()
	end
end)

The problem is that the Transparency property of the ClonedS is a NumberSequence, not a number. Therefore, you can’t use <= to compare the two.

You can try changing to:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local smoke = ReplicatedStorage.ParticleSmoke.ParticleEmitter

--Function

local function BarrelShift()
	local ClonedS = smoke:Clone()
	ClonedS.Parent = player.Character:FindFirstChild("HumanoidRootPart")
	wait(1.3)
	while ClonedS.Transparency.Keypoints[1].Value >= 0.1 do
		ClonedS.Transparency = NumberSequence.new(ClonedS.Transparency.Keypoints[1].Value - 0.1)
		wait(0.1)
	end
	ClonedS:Destroy()
end
--UIS input function
UserInputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		BarrelShift()
	end
end)

This did fix my problem, but the transparency still stays the same?

Well that is a different issue. The problem is I don’t know your use case, so I can’t tell what’s happening there. I could only fix the code error that you provided.

If you give me more information, or maybe even share your project, I could help you to get it working :slight_smile: .

Information on this script: Located in StartPlayerScripts, This scripts main objective is to spawn particles on the Players HumanoidRootPart. This is all in the script right now, but its not exactly working… The problem is that when the particles go to despawn, they dont fade away, which was my objective with the transparency part of the script, which you already partially fixed.

Example: Example1
^This link goes to a gyazo video of the particle, and what happens.
The thing I want it to do is fade into a lower transparency before it completely deletes itself.

One this I found about this script is that when I added a Print statement to see if the loop worked, nothing showed up. SO it might not be the transparency, but the whole loop that isnt working

hopefully thats enough info for you
thank you for helping me c:

To lower the transparency in a loop, what I do is:

ClonedS.Transparency -= 0.5

I moved the script around a bit and this ended up working with just a bit of tweaking, thanks again

1 Like

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