I have a script that checks if a player is eligible to get a donator chat tag. But the script doesn’t work and I get a weird error message from chatservice…
lower is not a valid member of Player "Players.trueblockhead101" - Server - ChatService:169
while true do
wait()
game.Players.PlayerAdded:Connect(function(playerName)
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local Speaker = ChatService:GetSpeaker(playerName)
local player = game.Players[playerName]
local stat = player:WaitForChild("Donator")
if stat.Value == 1 then
Speaker:SetExtraData('Tags', {{TagText = "Donator", TagColor = Color3.fromRGB(124, 252, 0)}})
end
end)
end
And I don’t know how to fix that or how to get my script to work.
You’re attempting to pass a player to ChatService:GetSpeaker() which expects a string. players.PlayerAdded passes a player as the first argument. Also get rid of the loop as @JarodOfOrbiter said.
--//Services
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
--//Requires
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
--//Functions
Players.PlayerAdded:Connect(function(player)
local Speaker = ChatService:GetSpeaker(player.Name)
local stat = player:WaitForChild("Donator")
if stat.Value == 1 then
Speaker:SetExtraData('Tags', {{TagText = "Donator", TagColor = Color3.fromRGB(124, 252, 0)}})
end
end)
Also, never connect functions in a loop without disconnecting them. It will cause huge memory issues and will most likely lead to your game to crashing within minutes or even seconds. You also shouldn’t connect functions in a loop for most cases.
Try this instead: (sorry, I connected the wrong function on my first post)
--//Services
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
--//Requires
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
--//Functions
ChatService.SpeakerAdded:Connect(function(playerName)
local Player = Players:WaitForChild(playerName)
local stat = Player:WaitForChild("Donator")
if stat.Value == 1 then
local speaker = ChatService:GetSpeaker(playerName)
speaker:SetExtraData('Tags', {{TagText = "Donator", TagColor = Color3.fromRGB(124, 252, 0)}})
end
end)
local Mps = game:GetService("MarketplaceService")
local players = game.Players
local product id = 1272983101
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
print("Bought")
local stat = player:FindFirstChild("Donator")
stat.Value = 1
end
end
Mps.ProcessReceipt = processReceipt
and this is my datastore script (currently the donator value isn’t saved and i know why and I’ll fix it later)
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("playerData")
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Point = Instance.new("IntValue")
Point.Name = "Points"
Point.Parent = leaderstats
local Donator = Instance.new("IntValue") --Here
Donator.Name = "Donator"
Donator.Parent = player
local xp = Instance.new("IntValue")
xp.Name = "Xp"
xp.Parent = leaderstats
local playerUserId = player.UserId
local data = playerData:GetAsync("Player_"..playerUserId)
if data then
Point.Value = data['Points']
xp.Value = data['Xp']
Donator.Value = data['Donator']
else
Point.Value = 0
xp.Value = 0
Donator.Value = 0
end
end
local function onPlayerExit(player)
local player_stats = {}
if player then
for i, stat in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
player_stats[stat.Name] = stat.Value
end
playerData:SetAsync("Player_"..player.UserId, player_stats)
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
game:BindToClose(function()
local LastPlayer = nil
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local player_stats = {}
if player then
if player ~= LastPlayer then
for i, stat in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
player_stats[stat.Name] = stat.Value
end
end
playerData:SetAsync("Player_"..player.UserId, player_stats)
end
end
end)
Btw: I have to go so if I don’t respond that’s why.
Okay so, my current script works, but doesn’t detect if the player buys the item. Use my current script, but also change your MarketplaceService script to this:
--//Services
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local MarketplaceService = game:GetService("MarketplaceService")
--//Requires
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
--//Controls
local ProductId = 1272983101
--//Functions
MarketplaceService.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
local stat = player.Donator
stat.Value = 1
local speaker = ChatService:GetSpeaker(player.Name)
speaker:SetExtraData('Tags', {{TagText = "Donator", TagColor = Color3.fromRGB(124, 252, 0)}})
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end