How do i make a stringvalue's value appear on a nametag

yes, i tried post 16 solution but it doesnt work

humanoid.DisplayDistanceType = "None"

	--Main
	newtext.Parent = head
	newtext.Adornee = head
	uppertext.Text = player.Name --Changes the text to the player's name.

	  player.EquippedTitle.Changed:Connect(function()
		if char.Head:FindFirstChild("NameTag") then
			lowertext.Text = player.EquippedTitle.Value --This is that the text will say.
			lowertext.TextColor3 = Color3.fromRGB(103, 24, 245) --This is what the color of the text will be.
		end
	end
end)

end)

local rep = game:GetService(“ReplicatedStorage”)
local nametag = rep.NameTag

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)

	local head = char.Head
	local newtext = nametag:Clone() --Cloning the text.
	local uppertext = newtext.UpperText
	local lowertext = newtext.LowerText
	local humanoid = char.Humanoid
	
	humanoid.DisplayDistanceType = "None"

	--Main
	newtext.Parent = head
	newtext.Adornee = head
	uppertext.Text = player.Name --Changes the text to the player's name.

	player.EquippedTitle.Changed:Connect(function()
		if char.Head:FindFirstChild("NameTag") then
			lowertext.Text = player.EquippedTitle.Value --This is that the text will say.
			lowertext.TextColor3 = Color3.fromRGB(103, 24, 245) --This is what the color of the text will be.
		end
	end)
end)

end)

Still doesnt work :frowning:
Screen Shot 2021-02-06 at 9.59.24 AM Screen Shot 2021-02-06 at 9.59.38 AM

You should make the equip button change the text to Beginner, and when you press unequip, make it change to Guest

So like this?
Screen Shot 2021-02-06 at 10.05.43 AM

No. Revert it and wait a minute I am making a solution

– Variables
local rep = game:GetService(“ReplicatedStorage”)
local nametag = rep.NameTag

–functions
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
–Varibles
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid

	humanoid.DisplayDistanceType = "None"

	--Main
	newtext.Parent = head
	newtext.Adornee = head
	uppertext.Text = player.Name
	lowertext.Text = "Guest"
end)

end)

Then give me the button script and I will fix

alright heres the button script

local cost = 5
local titleVal = Instance.new("StringValue")
script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer

	if player.leaderstats.Wins.Value >= cost then
		player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost

		wait()
		script.Parent.Text = "Bought"
		titleVal.Name = script.Parent.Parent.Name
		titleVal.Parent = player.Inventory

		wait(0.1)
		script.Parent.Text = "Equip"

		print("You bought this title")

		script.Parent.MouseButton1Click:Connect(function()
			if script.Parent.Text == "Equip" then
				wait()
				script.Parent.Text = "Equipped"
				player.EquippedTitle.Value = script.Parent.Parent.Name
				if script.Parent.Text == "Equipped" then
					script.Parent.Text = "Unequip"
					script.Parent.MouseButton1Click:Connect(function()
						if script.Parent.Text == "Unequip" then
							wait()
							player.EquippedTitle.Value = ""
							script.Parent.Text = "Equip"	
						end
					end)
				end
			end
		end)
	end
end) 

local cost = 5
local titleVal = Instance.new(“StringValue”)
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer

if player.leaderstats.Wins.Value >= cost then
	player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost

	wait()
	script.Parent.Text = "Bought"
	titleVal.Name = script.Parent.Parent.Name
	titleVal.Parent = player.Inventory

	wait(0.1)
	script.Parent.Text = "Equip"

	print("You bought this title")

	script.Parent.MouseButton1Down:Connect(function()
		if script.Parent.Text == "Equip" then
			wait()
			script.Parent.Text = "Equipped"
			player.Character:WaitForChild("Head").NameTag.LowerText.Text = script.Parent.Parent.Name
			player.EquippedTitle.Value = script.Parent.Parent.Name
			if script.Parent.Text == "Equipped" then
				script.Parent.Text = "Unequip"
				script.Parent.MouseButton1Down:Connect(function()
					if script.Parent.Text == "Unequip" then
						wait()
						player.Character:WaitForChild("Head").NameTag.LowerText.Text = "Guest"
						player.EquippedTitle.Value = "Guest"
						player.EquippedTitle.Value = ""
						script.Parent.Text = "Equip"	
					end
				end)
			end
		end
	end)
end

end)

Should i delete the nametag script? well the other script

local cost = 5
local titleVal = Instance.new(“StringValue”)
script.Parent.MouseButton1Down:Connect(function()
local player = game.Players.LocalPlayer

if player.leaderstats.Wins.Value >= cost then
	player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost

	wait()
	script.Parent.Text = "Bought"
	titleVal.Name = script.Parent.Parent.Name
	titleVal.Parent = player.Inventory

	wait(0.1)
	script.Parent.Text = "Equip"

	print("You bought this title")

	script.Parent.MouseButton1Down:Connect(function()
		if script.Parent.Text == "Equip" then
			wait()
			script.Parent.Text = "Equipped"
			player.Character:WaitForChild("Head").NameTag.LowerText.Text = script.Parent.Parent.Name
			player.EquippedTitle.Value = script.Parent.Parent.Name
			if script.Parent.Text == "Equipped" then
				script.Parent.Text = "Unequip"
				script.Parent.MouseButton1Down:Connect(function()
					if script.Parent.Text == "Unequip" then
						wait()
						player.Character:WaitForChild("Head").NameTag.LowerText.Text = "Guest"
						player.EquippedTitle.Value = "Guest"
						player.EquippedTitle.Value = ""
						script.Parent.Text = "Equip"	
					end
				end)
			end
		end
	end)
end

end)

– and dont delete nametag script.

IT WORKS THX SO MUCH, and btw does this work with the other ones? cuz i have more titles

yes it works for every other one, just edit the button script and you can change costs

1 Like

You should put a value that saves, to check if you already bought it

alright im going to make a datastore thanks so much!!

I can make one for you so you don’t have to have any errors

really?? if thats ok with you im fine with that

If you are going to then can you use it on this script?

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local MyDataStore = DataStoreService:GetDataStore("Wins")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats
	
	local Inventory = Instance.new("Folder")
	Inventory.Name = "Inventory"
	Inventory.Parent = player
	
	local EquippedTitle = Instance.new("StringValue")
	EquippedTitle.Name = "EquippedTitle"
	EquippedTitle.Parent = player
	
	local data
	local success, errormessage = pcall(function()
		data = MyDataStore:GetAsync(player.UserId.."-wins")
	end)
	
	if success then
		Wins.Value = data
	else
		print("There was an error whilst saving your data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		MyDataStore:SetAsync(player.UserId.."-wins",player.leaderstats.Wins.Value)
	end)
	
	if success then
		print("Saved Successfully")
	else
		print("There was an error saving data")
		warn(errormessage)
	end
end)