How do i make this run more than once?

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if true then
			local titleScroll = plr.PlayerGui:WaitForChild("TitlesGui"):WaitForChild("TitlesFrame"):WaitForChild("TitlesScroll")
			titleScroll:WaitForChild("StarterTitleFrame"):WaitForChild("EquipButton").MouseButton1Click:Connect(function()
				if true then
					local leaderstats = plr.leaderstats
					if leaderstats.kills.Value > 0 and leaderstats.wins.Value > 0 then
						local starterTitle = titles.StarterTitleGui:Clone()
						local originalTitle = char:WaitForChild("Head"):FindFirstChildWhichIsA("BillboardGui")
						if originalTitle then
							originalTitle:Destroy()
						end
						starterTitle.Parent = char:WaitForChild("Head")
						plr.CharacterAdded:Connect(function(newChar)
							if true then
								task.wait(0.5)
								local starterTitle2 = titles.StarterTitleGui:Clone()
								local originalTitle2 = newChar:WaitForChild("Head"):FindFirstChildWhichIsA("BillboardGui")
								if originalTitle2 then
									originalTitle2:Destroy()
								end
								starterTitle2.Parent = newChar:WaitForChild("Head")
							end
						end)
						titleScroll.StarterTitleFrame.EquipButton.Text = "Equipped"
						task.wait(3)
						titleScroll.StarterTitleFrame.EquipButton.Text = "Equip"
					else
						plr.PlayerGui.AntiEquipGui.Enabled = true
						task.wait(3)
						plr.PlayerGui.AntiEquipGui.Enabled = false
					end
				end
			end)
		end
	end)
end)

how can i transform this script so that it runs more than once? ive tried making it a while loop, that didnt work

edit: to clarify, i want this script to run whenever the player dies (NOT when the player respawns however)

12 Likes

Make a function, put the code you want to run twice inside it, and call the function two times

5 Likes

Or you could use while true do

2 Likes

Or you could do a for i = function.

3 Likes

tried that, it didnt work tho sadly

2 Likes

alr tried that, stated that in the post; it didnt work

im a beginner scripter, so mb if while true do and while loops are different lol

1 Like

tried it, unfortunately didnt work either

1 Like

I don’t know about the if true then statement is that really necessary?
anyway just saying. Have you tried to print in every statement so you can see which one is acting wrong?

1 Like

tried that. apparently it went wrong at the introduction of the titleScroll. theres an output error, saying startertitleframe is not the child of titlescroll, when it is??? theres nothing else named “startertitleframe” either

2 Likes

huh weird at least we know why it didn’t loop.
And i think this is a server script which can not reach to player gui
You should fire an event when button pressed instead

Edit: I see people still able to do it on server side and they add Player:WaitForChild(“PlayerGui”) instead of Player.PlayerGui

2 Likes

Habe oyou tried looping only non-intro code? If you loop one-time-use code, you’ll get an error. (And stop the loop)

Edit: is this a nametag script? I can’t tell…

2 Likes

tried waitforchild, nothing changed

2 Likes

idk what you mean by that, but this is a nametag/title script

2 Likes

Can you take a screenshot in explorer then it might help something

1 Like

When do you want the script to run? Since right now, your script will only run whenever the character resets.

1 Like

If so then you can probably try just modifying it to place the GUI using StarterCharacterScripts. That’s what I did for my game and it works well.

1 Like

Tried cleaning your script in hopes of fixing it, good luck:

--LocalScript inside game.StarterPlayer.StarterCharacterScripts
local titles = --path to titles
local Character = script.Parent
local Player = game.Players.LocalPlayer 
local UI = Player:FindFirstChildWhichIsA("PlayerGui")

local frame = UI:WaitForChild("TitlesGui"):WaitForChild("TitlesFrame"):WaitForChild("TitlesScroll"):WaitForChild("StarterTitleFrame")
frame:WaitForChild("EquipButton").MouseButton1Click:Connect(function()
	if Player.leaderstats.kills.Value > 0 and Player.leaderstats.wins.Value > 0 then
		local Head = Character:WaitForChild("Head")
		local originalTitle = Head:FindFirstChildWhichIsA("BillboardGui")
		if originalTitle then originalTitle:Destroy() end
		titles.StarterTitleGui:Clone().Parent = Head 
		frame.EquipButton.Text = "Equipped"
		task.wait(3)
		frame.EquipButton.Text = "Equip"
	else
		UI.AntiEquipGui.Enabled = true
		task.wait(3)
		UI.AntiEquipGui.Enabled = false
	end
end)

well the script is in serverscriptservice, idk how helpful that is tho

it is a server script

i want it to run when the character dies

which one? the title shop gui or the title gui