-
What do you want to achieve? Keep it simple and clear!
The title says it. -
What is the issue? Include screenshots / videos if possible!
Idk how to do it and i already tried for 2 hours. -
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.
local part = Instance.new("Part")
part.Parent = workspace
while task.wait() do
for i = 0, 255 do
task.wait()
part.Color = Color3.new(i, i, i)
end
for i = 255, 0, -1 do
task.wait()
part.Color = Color3.new(i, i, i)
end
end
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)
Yes you could alternatively use TweenService, I went with a more primitive solution, however bare in mind your tween could end up playing too frequently if too many CharacterAdded events are stacked. Use the .Completed event to prevent this from happening.
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
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)()
You could try using TweenService
, or use Color3:lerp
(which may be more resource-efficient but not as smooth and the former).
It worked, thank you so much!