How could i change my tool instance.new beam color smoothly and repeatedly

  1. What do you want to achieve? Keep it simple and clear!
    The title says it.
  2. What is the issue? Include screenshots / videos if possible!
    Idk how to do it and i already tried for 2 hours.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried looking tutorials, script it myself and search in the devforum.
1 Like

Hey, thanks for replying i should have said this:
i want this for a gaster blaster thing, my goal its to make the gaster blaster ray to change color from really blue to really black constantly and smoothly every .2 seconds heres the code:

local c = Instance.new("Part", script.Parent)
	c.Name = "GasterBeam"
	c.Anchored = true
	c.Shape = Enum.PartType.Cylinder
	c.Size = Vector3.new(0, script.Parent.BeamCharging.Size.Y * 2, script.Parent.BeamCharging.Size.Z * 2)
	c.Material = Enum.Material.Neon
	c.Transparency = script.Parent["Beam Transparency"].Value

Or instead, just use TweenService.

--//Services
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

--//Variables
local part = workspace.Part -- Reference your part
local Info = TweenInfo.new(3) -- Seconds it takes to complete the tween
local Tween = TweenService:Create(part, Info, {Color = Color3.fromRGB(0, 0, 0)}) -- Colour your part will change into

--//Functions
game:GetService("Players").PlayerAdded:Connect(function(player) -- Will play the tween every time a character loads in
	player.CharacterAdded:Connect(function()
		Tween:Play()
        Tween.Completed:Wait()
	end)
end)
1 Like

Yea, forgot to add that, thanks for correcting me.

For your situation do this:

local TweenService = game:GetService("TweenService")

local c = Instance.new("Part") -- You shouldn't use the second argument of Instance.new()
c.Name = "GasterBeam"
c.Anchored = true
c.Shape = Enum.PartType.Cylinder
c.Size = Vector3.new(0, script.Parent.BeamCharging.Size.Y * 2, script.Parent.BeamCharging.Size.Z * 2)
c.Material = Enum.Material.Neon
c.Transparency = script.Parent["Beam Transparency"].Value
c.Parent = script.Parent

local Tween1 = TweenService:Create(c, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 0)}) -- Colour your part black
local Tween2 = TweenService:Create(c, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 255)}) -- Colour your part blue

while true do
 Tween1:Play() -- Colour your part black
 Tween1.Completed:Wait()
 Tween2:Play() -- Colour your part blue
 Tween2.Completed:Wait()
end

Video of what should happen: video of what should happen

1 Like

for some reazon it doesnt work ill send the entire shoot code (what happens its that the ray doesnt appear)

while true do
	local p = Instance.new("Part", script.Parent)
	p.Name = "ChargingAura"
	p.Anchored = true
	p.CFrame = script.Parent.BeamCharging.CFrame
	p.Shape = Enum.PartType.Ball
	p.BrickColor = script.Parent["Beam color"].Value
	p.Size = Vector3.new(script.Parent.BeamCharging.Size.X * 2.5, script.Parent.BeamCharging.Size.X * 2.5, script.Parent.BeamCharging.Size.X * 2.5)
	p.Material = Enum.Material.Neon
	p.Transparency = 1
	p.CanCollide = false
	script.Parent.Beamer.Charge:Play()
	for i = 1,20 do
		p.Size = p.Size - Vector3.new(script.Parent.BeamCharging.Size.X * 0.075, script.Parent.BeamCharging.Size.X * 0.075, script.Parent.BeamCharging.Size.X * 0.075)
		p.Transparency = p.Transparency - 0.0375
		script.Parent.Jaws.CFrame = script.Parent.Jaws.CFrame * CFrame.Angles(math.rad(2.25), math.rad(0), math.rad(0))
		wait(0.025)
	end
	game.Debris:AddItem(p, 0.5)
	wait(0.5)
	local TweenService = game:GetService("TweenService")

	local c = Instance.new("Part") -- You shouldn't use the second argument of Instance.new()
	c.Name = "GasterBeam"
	c.Anchored = true
	c.Shape = Enum.PartType.Cylinder
	c.Size = Vector3.new(0, script.Parent.BeamCharging.Size.Y * 2, script.Parent.BeamCharging.Size.Z * 2)
	c.Material = Enum.Material.Neon
	c.Transparency = script.Parent["Beam Transparency"].Value
	c.Parent = script.Parent

	local Tween1 = TweenService:Create(c, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 0)}) -- Colour your part black
	local Tween2 = TweenService:Create(c, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 255)}) -- Colour your part blue

	while true do
		Tween1:Play() -- Colour your part black
		Tween1.Completed:Wait()
		Tween2:Play() -- Colour your part blue
		Tween2.Completed:Wait()
	end
	c.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= script.Parent.Creator.Value then
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.Damage.Value)
		end
	end)
	script.Parent["Right Eye"].Transparency = 1
	script.Parent.Beamer.Shoot:Play()
	for i = 1,10 do
		c.Size = c.Size + Vector3.new(script.Parent.BeamCharging.Size.X * 10, script.Parent.BeamCharging.Size.Y / 20, script.Parent.BeamCharging.Size.Y / 20)
		c.Transparency = c.Transparency + 0.025
		c.CFrame = script.Parent.BeamCharging.CFrame + script.Parent.BeamCharging.CFrame.RightVector * ((c.Size.X / 2) + (script.Parent.BeamCharging.Size.X * 1.5))
		c.CanCollide = false
		wait(0.025)
		
	end
	for i = 1 , 2 do
		for i = 1,10 do
		c.Size = c.Size - Vector3.new(-(script.Parent.BeamCharging.Size.X * 2), script.Parent.BeamCharging.Size.Y / 20, script.Parent.BeamCharging.Size.Y / 20)
		c.CFrame = script.Parent.BeamCharging.CFrame + script.Parent.BeamCharging.CFrame.RightVector * ((c.Size.X / 2) + (script.Parent.BeamCharging.Size.X * 1.5))
		c.Transparency = c.Transparency - 0.025
		wait(0.025)
		
		end
			for i = 1,10 do
		c.Size = c.Size + Vector3.new(script.Parent.BeamCharging.Size.X * 2, script.Parent.BeamCharging.Size.Y / 20, script.Parent.BeamCharging.Size.Y / 20)
		c.CFrame = script.Parent.BeamCharging.CFrame + script.Parent.BeamCharging.CFrame.RightVector * ((c.Size.X / 2) + (script.Parent.BeamCharging.Size.X * 1.5))
		c.Transparency = c.Transparency + 0.025
		wait(0.025)
		
			end
			wait()
	end
		for i = 1,10 do
		c.Size = c.Size - Vector3.new(-(script.Parent.BeamCharging.Size.X * 2), script.Parent.BeamCharging.Size.Y / 4, script.Parent.BeamCharging.Size.Z / 4)
		c.CFrame = script.Parent.BeamCharging.CFrame + script.Parent.BeamCharging.CFrame.RightVector * ((c.Size.X / 2) + (script.Parent.BeamCharging.Size.X * 1.5))
		c.Transparency = c.Transparency - 0.025
		wait(0.025)
		
		end
	
	game.Debris:AddItem(c, 0)
	script.Parent["Right Eye"].Transparency = 0
		for i = 1,20 do
		script.Parent.Jaws.CFrame = script.Parent.Jaws.CFrame * CFrame.Angles(math.rad(-2.25), math.rad(0), math.rad(0))
		wait(0.025)
		end
		script.Parent.Beamer.Bling:Play()
	wait(0.5)
end

Switch my while true do loop with this.

coroutine.wrap(function()
	while true do
		Tween1:Play() -- Colour your part black
		Tween1.Completed:Wait()
		Tween2:Play() -- Colour your part blue
		Tween2.Completed:Wait()
	end
end)()
1 Like

You could try using TweenService, or use Color3:lerp (which may be more resource-efficient but not as smooth and the former).

1 Like

It worked, thank you so much! :slight_smile:

1 Like