Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to cast value to object for VIP shirt donator tag?

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!

5 comments

0

Try putting it on another services (replicatedstorage, workspace etc...)

0

Putting it in ReplicatedStorage instead of ServerScriptService stops the error from occuring, but it still doesn't change the textcolor. It gives no errors anymore though however!

0

local plrs = game.Players is completely redundant if you're not going to use that variable.

0

:PlayerOwnsAsset requires a player as an argument. Plr is an object since it contains information from localplayer. LocalPlayer is an object/instance.

0

Ideally, this should be a reference to the player not the localplayer, since localplayer doesn't take any arguments/parameters

1 answer

✓ Accepted answer

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)

2 comments

0

This works perfectly! Thank you very much!

0

You're very welcome!

This discussion is preserved as it was. New answers, comments, and votes are closed.