I need help with my script

Where is my mistake in the script?

local Players = game:GetService("Players")
local ServerScriptService = game:GetService('ServerScriptService')
local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local function onPlayerChatted(PlayerName)
	local value = Players.LocalPlayer:WaitForChild("VIP")
	if value.Value == true then
		local Speaker = ChatService:GetSpeaker(PlayerName)
		Speaker:SetExtraData('Tags', {{TagText = 'VIP', TagColor = Color3.fromRGB(255, 255, 0)}})
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 247, 0))
	end	
end

ChatService.SpeakerAdded:Connect(onPlayerChatted)
2 Likes

Is this in a Server Script? or Local Script?

the script is server script and is in ServerScriptService

Seems like you’re using LocalPlayer in a server script. You can’t do this, accessing the LocalPlayer can only be done on the client.

You are able to retrieve the speaker from the SpeakerAdded event instead.

local Players = game:GetService("Players")
local ServerScriptService = game:GetService('ServerScriptService')
local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local function onPlayerChatted(PlayerName)
	local value = game.Players:FindFirstChild(PlayerName):WaitForChild("VIP")
	if value.Value == true then
		local Speaker = ChatService:GetSpeaker(PlayerName)
		Speaker:SetExtraData('Tags', {{TagText = 'VIP', TagColor = Color3.fromRGB(255, 255, 0)}})
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 247, 0))
	end	
end

ChatService.SpeakerAdded:Connect(function(speakerName)
    onPlayerChatted(speakerName)
end)

Try this out and let me know if it works

it’s not working. thanks for trying

Is there an error, if there is what is it?

this is the error:

Instead of doing value.Value on line 6, try

if value == true then

Hey, I played around with your script and came up with this. It’s working just fine, let me know if it’s useful

local Players = game:GetService("Players")
local ServerScriptService = game:GetService('ServerScriptService')
local MarketplaceService = game:GetService('MarketplaceService')
local passId = 000 -- Gamepass ID

Players.PlayerAdded:Connect(function(Player)
	local Bool = Instance.new('BoolValue')
	Bool.Parent = Player
	Bool.Name = 'VIP'

	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,passId) then
		Bool.Value = true
	end
end)

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local function onPlayerChatted(PlayerName)
	local value = game.Players:FindFirstChild(PlayerName):WaitForChild("VIP")
	if value.Value == true then
		local Speaker = ChatService:GetSpeaker(PlayerName)
		Speaker:SetExtraData('Tags', {{TagText = 'VIP', TagColor = Color3.fromRGB(255, 255, 0)}})
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 247, 0))
	end	
end

ChatService.SpeakerAdded:Connect(function(speakerName)
	onPlayerChatted(speakerName)
end)

it’s not working
:frowning: :frowning: :frowning: