Hey!
I am in a bit of a pickle with making my Rainbow Nametag Gamepass work properly.
I have gotten it to work although I can’t imagine the code is super good, since I cannot code to save my life I’ve done the next best thing and I’ve recruited ChatGPT and YouTube tutorials to write it for me.
Anyway, now to the reason I’m asking all of you talented developers for help:
When a player who has the gamepass plays my game alone, it works fine.
But whenever there are multiple players the player with the gamepass loses the rainbow effect and it turns into the standard white name tag thats meant for the players who dont own the gamepass.
From what ChatGPT told me, this is due to the script not checking for the gamepass to see if its owned or not whenever a player joins/dies.
Well, turns out ChatGPT couldnt fix the issue after countless prompts.
So now when AI can’t solve the problem, I’m hoping one of you can.
The Nametag system uses 2 scripts, one to create the name tag and one to add the rainbow effect to the textlabels inside the billboardgui.
Heres the nametag script:
local groupid = 9264123
game.Players.PlayerAdded:Connect(OnPlayerRespawned)
function OnPlayerRespawned(player)
wait(1)
if player then
local tag = script.Parent.PlayerNametag:Clone()
tag.Main.PlayerName.Text = player.Name
tag.Main.GroupRank.Text = player:GetRoleInGroup(groupid)
-- Create a fixed-size BillboardGui
local billboardGui = tag:FindFirstChild("BillboardGui")
if billboardGui then
-- Set the BillboardGui size to a fixed size
billboardGui.Size = UDim2.new(0, 200, 0, 50) -- Fixed size (adjust as needed)
billboardGui.MaxDistance = 30 -- Max distance before the GUI disappears
billboardGui.Adornee = player.Character.Head -- Attach to the character's head
billboardGui.StudsOffset = Vector3.new(0, 2, 0) -- Adjust offset if needed
-- Turn off scaling and ensure it doesn't scale with distance
billboardGui.AlwaysOnTop = true -- Keep the UI above other objects in the game
-- Adjust the text size to be fixed regardless of camera zoom
local playerNameText = tag.Main.PlayerName
local groupRankText = tag.Main.GroupRank
-- Set the text size to be a fixed value
playerNameText.TextSize = 18 -- Adjust text size as needed (smaller size)
groupRankText.TextSize = 16 -- Adjust text size for GroupRank as needed
end
tag.Parent = player.Character.Head -- Parent the tag to the player's head
end
end
function OnPlayerEntered(player)
player.Changed:Connect(function(property)
if (property == "Character") then
OnPlayerRespawned(player)
end
end)
end
game.Players.PlayerAdded:Connect(OnPlayerEntered)
Heres the rainbow nametag script:
local RS = game:GetService("RunService")
local rainbow = script.Parent
local grad = rainbow.UIGradient
local counter = 0
local w = math.pi / 6
local CS = {}
local num = 15
local frames = 0
local count = 0
local cskCache = {}
local gamepassid = 1019274864
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid) then
print("Rainbow nametag")
else
grad:Destroy()
end
end)
while true do
for i = 0, num do
local c = Color3.fromRGB(127 * math.sin(w*i + counter) + 128, 127 * math.sin(w*i + 2 * math.pi/3 + counter) + 128, 127*math.sin(w*i + 4*math.pi/3 + counter) + 128)
table.insert(CS, i+1, ColorSequenceKeypoint.new(i/num, c))
end
local newCS = ColorSequence.new(CS)
if #cskCache > 0 then
if newCS == cskCache[1] then
CS = {}
break
end
end
table.insert(cskCache, newCS)
CS = {}
counter = counter + math.pi/40
if (counter >= math.pi * 2) then counter = 0 end
end
local finalCacheCt = #cskCache
local rotation = 1
RS.Heartbeat:Connect(function()
if math.fmod(frames, 2) == 0 then
grad.Color = cskCache[rotation]
if rotation >= #cskCache then rotation = 0 end
rotation = rotation + 1
end
if frames >= 1000 then frames = 0 end
frames = frames + 1
end)
I know the code is most likely a mess, but I’m not a scripter so it’s difficult for me to do a better job myself, so I had no choice in the matter.
Please help me fix this issue, I really have no clue what’s wrong.