How to add an object to the character after pressing a button in-game?

hi, i am a beginner developer, and i am making a title shop. however, when you equip a title, it disappears after respawn. i have no idea how to fix this, i tried adding it to the added character but that didnt work. i have no more solutions i can come up with so please help

this is in a server script

1 Like

Can you share your current script that you have so far?

none. i have no idea where to start as i am a beginner and am clueless

Are you making it a GUI store or a walk in store?(Like a clothing store)

there is a button on a death screen that activates a title shop gui (i already made most of it work, i just dont know how to make the titles stay on the character after respawn)

The title hovering over the head of the player?

yes, i dont mean chat tags or anything, the title that goes over the players head, yes

Try this:

local DataStoreService = game:GetService(“DataStore”)
local TitleDataStore = DataStoreService:GetDataStore(“EquippedTitles”)

local function saveTitleOnReset(player)
local character = player.Character
if character then
local equippedTitle = character:FindFirstChild(“TitleBillboard”)
if equippedTitle then
local titleText = equippedTitle.TitleText.Text
TitleDataStore:SetAsync(player.UserId, titleText)
end
end
end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
– Remove any previous title when the player respawns
local oldTitle = character:FindFirstChild(“TitleBillboard”)
if oldTitle then
oldTitle:Destroy()
end

    -- Load the equipped title when the player respawns
    local equippedTitle = TitleDataStore:GetAsync(player.UserId)
    if equippedTitle then
        -- Create a BillboardGui to display the title
        local billboardGui = Instance.new("BillboardGui")
        billboardGui.Name = "TitleBillboard"
        billboardGui.Adornee = character.Head
        billboardGui.ExtentsOffset = Vector3.new(0, 1, 0)
        billboardGui.Size = UDim2.new(0, 200, 0, 50)

        local titleTextObj = Instance.new("TextLabel")
        titleTextObj.Name = "TitleText"
        titleTextObj

It wont save after joining a new server but should work when you die or reset

1 Like

tried it, now nothing works at all

1 Like

i made a new script, but, as expected, the same thing happened. i wonder how i can alter this so that the title remains on the character after respawning?

local titles = game.ReplicatedStorage.Titles

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.StarterTitleFrame.EquipButton.MouseButton1Click:Connect(function()
				if true then
					local leaderstats = plr.leaderstats
					if leaderstats.kills.Value > 0 and leaderstats.wins.Value > 0 then
						local originalTitle = char:WaitForChild("Head"):FindFirstChildWhichIsA("BillboardGui")
						if originalTitle then
							originalTitle:Destroy()
						end
						titles.StarterTitleGui:Clone().Parent = char:WaitForChild("Head")
						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)

fixed it!!! just added another characteradded and it worked the way i wanted it to

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.