Hey, i want to make so this entire script do without making delay on next lines?, can somebody help. it isnt working!
for _, v in pairs(game.ReplicatedStorage.Items.PlateCosmetics:GetChildren()) do
if v.Name == player.PlateCosmeticEquippedSlot1.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
elseif v.Name == player.PlateCosmeticEquippedSlot2.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
elseif v.Name == player.PlateCosmeticEquippedSlot3.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
end
end
Look into Coroutines. They help a lot in these cases, if I understand your problem.
Basically, they allow you to run code on a different thread, aka at the (almost) same time as other code in the same script.
I’ll show you how to use coroutine.wrap() in this case:
coroutine.wrap(function(
for _, v in pairs(game.ReplicatedStorage.Items.PlateCosmetics:GetChildren()) do
if v.Name == player.PlateCosmeticEquippedSlot1.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
elseif v.Name == player.PlateCosmeticEquippedSlot2.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
elseif v.Name == player.PlateCosmeticEquippedSlot3.Value then
local comseticclone = v:Clone()
comseticclone.Parent = plate
task.spawn(function()
while game.ReplicatedStorage.Round.Value == true do
comseticclone:SetPrimaryPartCFrame(plate.Part.CFrame + Vector3.new(0,1,0))
end
end)
end
end
))()