So I have made a fully working title shop and would like it if some of you guys would review my script. I feel like it is very long and there has to be a better way of doing this!
game.Players.PlayerAdded:Connect(function(player)
game.Workspace.ChildAdded:Connect(function(character)
local ServerStorage = game:GetService('ServerStorage')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local CosmeticEvents = ReplicatedStorage:WaitForChild('CosmeticEvents')
local PlayerStats = player:WaitForChild('PlayerStats')
--//Stats\\--
local Coins = PlayerStats:WaitForChild('Coins')
--//Cosmetics\\--
local nameTag = game:GetService('ServerStorage'):WaitForChild('NameTag')
local currentTag
local NoviceTitle = PlayerStats:WaitForChild('NoviceTitle')
local RookieTitle = PlayerStats:WaitForChild('RookieTitle')
local BeginnerTitle = PlayerStats:WaitForChild('BeginnerTitle')
local AmatuerTitle = PlayerStats:WaitForChild('AmatuerTitle')
local IntermediateTitle = PlayerStats:WaitForChild('IntermediateTitle')
local TalentedTitle = PlayerStats:WaitForChild('TalentedTitle')
local SkilledTitle = PlayerStats:WaitForChild('SkilledTitle')
local SeasonedTitle = PlayerStats:WaitForChild('SeasonedTitle')
local ProficientTitle = PlayerStats:WaitForChild('ProficientTitle')
local ExperiencedTitle = PlayerStats:WaitForChild('ExperiencedTitle')
local AdvancedTitle = PlayerStats:WaitForChild('AdvancedTitle')
local SeniorTitle = PlayerStats:WaitForChild('SeniorTitle')
local ExpertTitle = PlayerStats:WaitForChild('ExpertTitle')
local OwnerTitle = PlayerStats:WaitForChild('OwnerTitle')
--//Remote Events\\--
local NoviceTitleEvent = CosmeticEvents:WaitForChild('NoviceTitleEvent')
local RookieTitleEvent = CosmeticEvents:WaitForChild('RookieTitleEvent')
local BeginnerTitleEvent = CosmeticEvents:WaitForChild('BeginnerTitleEvent')
local AmatuerTitleEvent = CosmeticEvents:WaitForChild('AmatuerTitleEvent')
local IntermediateTitleEvent = CosmeticEvents:WaitForChild('IntermediateTitleEvent')
local TalentedTitleEvent = CosmeticEvents:WaitForChild('TalentedTitleEvent')
local SkilledTitleEvent = CosmeticEvents:WaitForChild('SkilledTitleEvent')
local SeasonedTitleEvent = CosmeticEvents:WaitForChild('SeasonedTitleEvent')
local ProficientTitleEvent = CosmeticEvents:WaitForChild('ProficientTitleEvent')
local ExperiencedTitleEvent = CosmeticEvents:WaitForChild('ExperiencedTitleEvent')
local AdvancedTitleEvent = CosmeticEvents:WaitForChild('AdvancedTitleEvent')
local SeniorTitleEvent = CosmeticEvents:WaitForChild('SeniorTitleEvent')
local ExpertTitleEvent = CosmeticEvents:WaitForChild('ExpertTitleEvent')
local OwnerTitleEvent = CosmeticEvents:WaitForChild('OwnerTitleEvent')
local clone = nameTag:Clone()
clone.Enabled = true
clone.Parent = character.Head
clone.Frame.TextLabel.Text = character.Name
if player.MembershipType == Enum.MembershipType.Premium then
clone.Frame.TextLabel.TextColor3 = Color3.fromRGB(70, 70, 70)
clone.Frame.TextLabel.Text = '✨Premium '..character.Name
end
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,27136394) then
clone.Frame.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
clone.Frame.TextLabel.Text = '👑VIP '..character.Name
end
if player.UserId == 514422896 then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,0,0)">Owner</font>]]
currentTag = clone.Frame.TextLabel.Text
else
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,255,0)">Noob</font>]]
currentTag = clone.Frame.TextLabel.Text
end
NoviceTitleEvent.OnServerEvent:Connect(function()
if NoviceTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,255,255)">Novice</font>]]
elseif Coins.Value >= 500 and NoviceTitle.Value == false then
Coins.Value -= 500
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,255,255)">Novice</font>]]
NoviceTitle.Value = true
end
end)
RookieTitleEvent.OnServerEvent:Connect(function()
if RookieTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,255,180)">Rookie</font>]]
elseif Coins.Value >= 1000 and RookieTitle.Value == false then
Coins.Value -= 1000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,255,180)">Rookie</font>]]
RookieTitle.Value = true
end
end)
BeginnerTitleEvent.OnServerEvent:Connect(function()
if BeginnerTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(130,193,255)">Beginner</font>]]
elseif Coins.Value >= 1500 and BeginnerTitle.Value == false then
Coins.Value -= 1500
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(130,193,255)">Beginner</font>]]
BeginnerTitle.Value = true
end
end)
AmatuerTitleEvent.OnServerEvent:Connect(function()
if AmatuerTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,132,130)">Amatuer</font>]]
elseif Coins.Value >= 2000 and AmatuerTitle.Value == false then
Coins.Value -= 2000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,132,130)">Amatuer</font>]]
AmatuerTitle.Value = true
end
end)
IntermediateTitleEvent.OnServerEvent:Connect(function()
if IntermediateTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(105,255,223)">Intermediate</font>]]
elseif Coins.Value >= 3000 and IntermediateTitle.Value == false then
Coins.Value -= 3000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(105,255,223)">Intermediate</font>]]
IntermediateTitle.Value = true
end
end)
TalentedTitleEvent.OnServerEvent:Connect(function()
if TalentedTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,130,166)">Talented</font>]]
elseif Coins.Value >= 4000 and TalentedTitle.Value == false then
Coins.Value -= 4000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,130,166)">Talented</font>]]
TalentedTitle.Value = true
end
end)
SkilledTitleEvent.OnServerEvent:Connect(function()
if SkilledTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,150,80)">Skilled</font>]]
elseif Coins.Value >= 5000 and SkilledTitle.Value == false then
Coins.Value -= 5000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,150,80)">Skilled</font>]]
SkilledTitle.Value = true
end
end)
SeasonedTitleEvent.OnServerEvent:Connect(function()
if SeasonedTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(0,150,255)">Seasoned</font>]]
elseif Coins.Value >= 7500 and SeasonedTitle.Value == false then
Coins.Value -= 7500
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(0,150,255)">Seasoned</font>]]
SeasonedTitle.Value = true
end
end)
ProficientTitleEvent.OnServerEvent:Connect(function()
if ProficientTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(80,255,80)">Proficient</font>]]
elseif Coins.Value >= 10000 and ProficientTitle.Value == false then
Coins.Value -= 10000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(80,255,80)">Proficient</font>]]
ProficientTitle.Value = true
end
end)
ExperiencedTitleEvent.OnServerEvent:Connect(function()
if ExperiencedTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(208,160,255)">Experienced</font>]]
elseif Coins.Value >= 15000 and ExperiencedTitle.Value == false then
Coins.Value -= 12500
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(208,160,255)">Experienced</font>]]
ExperiencedTitle.Value = true
end
end)
AdvancedTitleEvent.OnServerEvent:Connect(function()
if AdvancedTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,0,127)">Advanced</font>]]
elseif Coins.Value >= 15000 and AdvancedTitle.Value == false then
Coins.Value -= 15000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(255,0,127)">Advanced</font>]]
AdvancedTitle.Value = true
end
end)
SeniorTitleEvent.OnServerEvent:Connect(function()
if SeniorTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(135,90,67)">Senior</font>]]
elseif Coins.Value >= 17500 and SeniorTitle.Value == false then
Coins.Value -= 17500
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(135,90,67)">Senior</font>]]
SeniorTitle.Value = true
end
end)
ExpertTitleEvent.OnServerEvent:Connect(function()
if ExpertTitle.Value == true then
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(150,0,0)">Expert</font>]]
elseif Coins.Value >= 20000 and ExpertTitle.Value == false then
Coins.Value -= 20000
clone.Frame.TextLabel.Text = clone.Frame.TextLabel.Text..'\n'..[[<font color="rgb(150,0,0)">Expert</font>]]
ExpertTitle.Value = true
end
end)
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, id, purchased)
if id == 27136394 and purchased then
clone.Frame.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
clone.Frame.TextLabel.Text = '👑VIP '..currentTag
end
end)
end)
end)
Any recommendations are appreciated! (I can provide a place file if this is to hard to read.)
Basically there is a name tag that gets set to the players head when they join. Then if they have premium, the tag is set to say Premium and then the players name. If they own VIP then it is set to say VIP and the players name. From a shop they are able to purchase a title which fires the remote event to here. Then this script handles them buying the tag and equipping it. At the end of the script it also handles if they buy VIP in game.