No errors.

Im trying to make a script that displays the players diseases, showing their name and how many seconds left there are before it goes away, the problem is that it waits 10 seconds (after the first disease goes away) before adding the second disease

ive been trying many things to fix but haven't had any luck..

Local script:

local gui = script.Parent
local frame = script.Parent.Frame
local tb_to_clone = gui.TextLabel
local plr = game.Players.LocalPlayer

function IsEven(num)
	return num % 2 == 0
end

function del(name,cln)
		while plr.Diseases:FindFirstChild(name) ~= nil do
		local amtttt = tostring(plr:FindFirstChild("Diseases"):FindFirstChild(name).Value)
		cln.Text = (name ..  ": " .. amtttt)
		wait(.1)
	end
	cln:Destroy()
end

function addd(name)
		local amt = game.Workspace.Playeramts:FindFirstChild(plr.Name)
	local cln = tb_to_clone:Clone()
	cln.Parent = frame
	print(amt.Value)
	if amt.Value == 1 then
		cln.Position = UDim2.new(-0.709,0,.5,0)
	else
		if IsEven(amt.Value)then
		local half = amt.Value/2
		for i,v in pairs(frame:GetChildren())do
			if i <= half then
				v.Position = UDim2.new(-0.709,0,-(.1*i - .5)+.05,0)
			else 
				v.Position = UDim2.new(-0.709,0,((i-half)*.1+.5)-.05,0)
			end
		end
		else
			for i,v in pairs(frame:GetChildren())do
				local half = amt.Value - 1
				if i == 1 then
					v.Position = UDim2.new(-0.709,0,.5,0)
				else
								if i <= half then
				v.Position = UDim2.new(-0.709,0,-(.1*i - .5)+.1,0)
			else 
				v.Position = UDim2.new(-0.709,0,((i-half)*.1+.5),0)
			end
				end
			end
		end
		
	end
	cln.Visible = true
	
	del(name,cln)
end

function adddisease(name)
	addd(name)
end

game.ReplicatedStorage.Remotes.AddDiseaseGUI.OnClientEvent:Connect(function(name)
	adddisease(name)
end)

Module for adding a disease:

local remote = game.ReplicatedStorage.Remotes.AddDiseaseGUI
local module = {}

function adpls(timeee,dis)
		while timeee > -1 do
	if timeee == 0 then
		dis:Destroy()
	else
		wait(1)
		timeee = timeee - 1
		dis.Value = timeee
	end
	
end
end

os.difftime(1,9)

function addd(player,name,timee)
		local folder = game.Workspace.Playeramts:FindFirstChild(player.Name)
	folder.Value = folder.Value + 1
	local dis = Instance.new("NumberValue")
	dis.Parent = player:FindFirstChild("Diseases")
	dis.Name = name
	dis.Value = timee
	remote:FireClient(player,name)
	local timeee = 0
	timeee = timee
	
	adpls(timeee,dis)
end

module.add = function(player,name,timee)
	addd(player,name,timee)
end

return module

Server script:

local mod = require(game.ServerScriptService.addingdisease)

wait(05)

mod.add(game.Players.Plieax,"[redacted]",10)
mod.add(game.Players.Plieax,"b",10)
mod.add(game.Players.Plieax,"a",10)

2 comments

0

Hey, watch the content! We do not appreciate abusive or derogatory terms on our platform. Please review https://scriptinghelpers.org/help/community-guidelines

1

Boy is this code a mess. You might want to make the names of your functions and arguments more descriptive. Anyways, your problem is in the adpls() function. The function mod.add() calls this function and waits for the disease to end before adding the next disease. You need to use spawn() so it waits and deletes the disease at another thread, so mod.add() can directly add the next disease.