Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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!

0
Try putting it on another services (replicatedstorage, workspace etc...) Br0kenM1ndss 7 — 3y
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! FrigidusIncendium 24 — 3y
0
local plrs = game.Players is completely redundant if you're not going to use that variable. JesseSong 3916 — 3y
0
:PlayerOwnsAsset requires a player as an argument. Plr is an object since it contains information from localplayer. LocalPlayer is an object/instance. JesseSong 3916 — 3y
0
Ideally, this should be a reference to the player not the localplayer, since localplayer doesn't take any arguments/parameters JesseSong 3916 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
This works perfectly! Thank you very much! FrigidusIncendium 24 — 3y
0
You're very welcome! EnzoTDZ_YT 275 — 3y
Ad

Answer this question