Hey there! I have a tagcolor and custom tag system in my game that allows special users to have different chat and tag colors utilizing their player ID. Recently, I've been trying to script a VIP shirt that will also grant these benefits, but after finding a way to try and do it, I get the error that I am "Unable to cast value to object" and it gives me Line 12, which I will label below
local plr = game.Players.LocalPlayer local asset = 7246618473 --ShirtID local plrs = game.Players local sss = game.ServerScriptService local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService')) chatService.SpeakerAdded:Connect(function(plr) local speaker = chatService:GetSpeaker(plr) if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,asset) then--says Script 'ServerScriptService.Script', Line 12 print("Player owns shirt") speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255)) speaker:SetExtraData('Tags', {{TagText = 'Donator', TagColor = Color3.fromRGB(255, 255, 255)}}) else print("Player does not own shirt") end end)
I have never gotten this error before and everything about the script seems okay besides the error. It infact still prints that I own the shirt, but doesn't change the chatcolors or add the tag. Any help would be appreciated, thank you very much!
You are checking for localplayer something that the server can't handle. And chatService.SpeakerAdded returns the name of the speaker. Also put this as a normal script in serverscriptservice
local asset = 7246618473 --ShirtID local plrs = game.Players local sss = game.ServerScriptService local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService')) chatService.SpeakerAdded:Connect(function(plr) local speaker = chatService:GetSpeaker(plr) local player = game.Players:GetPlayerFromCharacter(workspace:FindFirstChild(plr)); -- Find player variable if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,asset) then -- Check if player owns it print("Player owns shirt") speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255)) speaker:SetExtraData('Tags', {{TagText = 'Donator', TagColor = Color3.fromRGB(255, 255, 255)}}) else print("Player does not own shirt") end end)