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

How do I check if a player owns two shirts or check for separate shirts to give a chat prefix?

Asked by 3 years ago

Hey all! I have a script for chat-tags that includes changing the prefix and textcolor for multiple users by ID as well as a system that detects whether or not a shirt is owned to give a prefix. The issue comes where if a user with special chat privileges (like me or my co-owner) joins, the entire script breaks. When the user is a normal player who owns both shirts or one shirt, it works perfectly fine. On the other hand, I got the script to work in a janky way by checking if the player owns both shirts, then the white shirt, then the black shirt. The script for normal players works but gives errors because of how I wrote the donation section of the script, and I want to know whether or not I should separate the custom tags from the donation tags script or if there is a way I can check for both shirts and separate shirts without causing error or breaking the script. I know this is really complicated, but I can't figure out a way to reliably fuse both into one script or to make the checks for donations shirts work properly without error and be consistent. Thank you for reading!

local asset = 7246616635 -- White donortag shirt ID is 7246616635
local asset2 = 7246617016 -- Black donortag shirt ID is 7246617016

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 plrs[plr].UserId == 27975160 then  -- Me!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(173, 58, 255)) 
--      
end
    --  
    if plrs[plr].UserId == 858674018 then  -- My one and only!~
        speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 251, 131))
        --
end

    --  
    if plrs[plr].UserId == 50326228 then  -- Sand!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(200, 255, 200))
        speaker:SetExtraData('Tags', {{TagText = 'The Council', TagColor = Color3.fromRGB(0, 255, 0)}}) 
        --
end

    --  
    if plrs[plr].UserId == 1856949685 then  -- DarDar!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(85, 170, 255))
        speaker:SetExtraData('Tags', {{TagText = 'The Council', TagColor = Color3.fromRGB(0, 85, 255)}})    
        --
end

    --  
    if plrs[plr].UserId == 1359587630 then  -- Nugget!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(148, 255, 198))
        speaker:SetExtraData('Tags', {{TagText = 'The Council', TagColor = Color3.fromRGB(0, 255, 127)}})   
        --
end

    --  
    if plrs[plr].UserId == 1808814883 then  -- Froggie!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(188, 255, 111))
        speaker:SetExtraData('Tags', {{TagText = 'Disciple', TagColor = Color3.fromRGB(170, 255, 0)}})  
        --
end

    --  
    if plrs[plr].UserId == 1564924300 then  -- TheWoodMan!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(170, 255, 255))
        speaker:SetExtraData('Tags', {{TagText = 'Contributor', TagColor = Color3.fromRGB(0, 170, 255)}})   
        --
end

    --  
    if plrs[plr].UserId == 13461533 then  -- Bingus Creator!
        speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 170, 255))
        speaker:SetExtraData('Tags', {{TagText = 'Contributor', TagColor = Color3.fromRGB(0, 170, 255)}})   
        --

    end
end)

----------------------Donor+ (Both shirts)

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,asset2) then -- Check if players userid owns both
        print("Player owns shirt")
        speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
        speaker:SetExtraData('Tags', {{TagText = 'Donator+', TagColor = Color3.fromRGB(143, 143, 143)}}) 
    else
        print("Player does not own both shirts")
    end
end)

----------------------DonorWhite

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 players userid owns white shirt
        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 white shirt")
    end
end)

---------------------DonorBlack

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,asset2) then -- Check if players userid owns black shirt
        print("Player owns shirt")
        speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
        speaker:SetExtraData('Tags', {{TagText = 'Donator', TagColor = Color3.fromRGB(22, 22, 22)}}) 
    else
        print("Player does not own black shirt")
    end
end)

Answer this question