So I’m trying to create a little error popup that constantly clones itself for 3 seconds and then stops but I have an issue where it just doesn’t clone
Here is my code:
edit: I managed to get 2 of the messages to show up but now it does it in like 2 second intervals.
local player = game.Players.LocalPlayer
wait(3)
local event = game.ReplicatedStorage.ErrorEffect
local errorgui = player.PlayerGui.Error
local holder = errorgui.Holder
local template = holder.Error
local sound = errorgui.Sound
local db = true
local function Del(Part)
wait(3)
Part:Destroy()
end
event.OnClientEvent:Connect(function()
errorgui.Enabled = true
sound:Play()
db = true
while db == true do
sound:Play()
local clone = template:Clone()
clone.Parent = holder
clone.Visible = true
local position = UDim2.new(math.random(0,500)/1000,0,math.random(0,500)/1000,0)
clone.Position = position
clone.ZIndex = math.random(1,20)
Del(clone)
end
end)
event.OnClientEvent:Connect(function()
wait(3)
db = false
end)
My Gui message is only showing in one area rather than cloning and moving to a different area.
its because math.random() only chooses whole numbers, so floats like your using wont work, a solution can be picking a number 0-10 and dividing the number by 10 so you get a random number, but its a decimal, you can extend this by also randomising the decimals by using 100 instead of 10.
local RandomFloat = math.random(0, 10) / 10
print(RandomFloat) -- prints 0-1, e.g 0.7
local RandomFloat = math.random(0, 100) / 100
print(RandomFloat) -- prints 0-1 but more precise, e.g 0.32
if you want something even more precise, use 1000 or more, but that’s just personal preference.
you have a task.wait(3) in the delete function so it’s yielding the loop. do this instead of calling Del:
task.delay(3,clone.Destroy,clone)
also I have no idea why you have 2 functions connected to event
edit: note that you have to put a task.wait in the loop, like task.wait(0.2), or it will error