local ReplicatedStorage = game.ReplicatedStorage
local Event = ReplicatedStorage.NicknameChangeEvent
local running = false
local function rainbow(thing, speed)
while true do
if running == true then
for i = 0, 1, 0.001 * speed do
if running == false then
break
end
thing.Color3 = Color3.fromHSV(i, 1, 1)
wait()
end
else
break
end
end
end
Event.OnServerEvent:Connect(function(plr, method, input)
local char = plr.Character
local descendants = char:GetDescendants()
if method == "Rainbow" then
if #descendants == 0 then return end
for i = 1, #descendants do
if descendants[i]:IsA("Decal") or descendants[i]:IsA("Texture") then
if descendants[i].Name ~= "Bucket" then
if input == true then
running = true
rainbow(descendants[i], 1)
else
running = false
end
end
end
end
end
end)
It works, it just only applies the rainbow effect to one decal at a time. How would I make it apply to EVERY decal it finds?
You could then use spawn or coroutine for multi-threading/running multiple functions in parallel (I suggest using coroutine since spawn() seems to have a little bit of delay)
local ReplicatedStorage = game.ReplicatedStorage
local Event = ReplicatedStorage.NicknameChangeEvent
local running = false
local function rainbow(thing, speed)
while true do
if running == true then
for i = 0, 1, 0.001 * speed do
if running == false then
break
end
thing.Color3 = Color3.fromHSV(i, 1, 1)
wait()
end
else
break
end
end
end
local bruh = coroutine.wrap(rainbow)
Event.OnServerEvent:Connect(function(plr, method, input)
local char = plr.Character
local descendants = char:GetDescendants()
if method == "Rainbow" then
if #descendants == 0 then return end
for i = 1, #descendants do
if descendants[i]:IsA("Decal") or descendants[i]:IsA("Texture") then
if descendants[i].Name ~= "Bucket" then
if input == true then
running = true
bruh(descendants[i], 1)
else
running = false
end
end
end
end
end
end)
Like this?
That’s as far as my knowledge of coroutines go lol
Still doesn’t work.
Running it in both these ways should run it I think, I usually used a different method to run coroutines but you can only actually get that answer from testing your code
There’s a service called CollectionService. You can use it to make couple of stuff to work with a 1 script. Moreover,
while true do
if running == true then
for i = 0, 1, 0.001 * speed do
if running == false then
break
end
thing.Color3 = Color3.fromHSV(i, 1, 1)
wait()
end
else
break
end
end
end
The while true do here is unnecessary since you have if running == true then..... Instead, you can do while running == true do…
And since you have if running == false then… You can change it to if not running then…