Hi all! So I’m trying to code when a player gets coins it notifies them! Here is my code yet I keep getting this error: “FireClient: Player argument must be player object”
local PlayerService = game:GetService("Players")
local CoinNotify = game.ReplicatedStorage.CoinNotify
local function SyncAPI(...)
CoinNotify:FireClient(PlayerService)
end
while true do
wait(2)
for _,player in pairs(game.Players:GetPlayers()) do
if player ~= nil then
local stats = player:FindFirstChild("leaderstats")
local cash = stats:FindFirstChild("Coins")
local amount = 200
cash.Value = cash.Value + amount
local title = "Payout!🤑"
local text = "You have recived "..amount.." Coins!🤑"
local image = ""
SyncAPI(title,text,image)
end
end
end
NOTE: it works fine with FireAllClients
when you are firing to a single client, agreement one must ALWAYS include the player, not the service “Players”
local PlayerService = game:GetService("Players")
local CoinNotify = game.ReplicatedStorage.CoinNotify
local function SyncAPI(what, what2, what3, player)
CoinNotify:FireClient(player, PlayerService)
end
while true do
wait(2)
for _,player in pairs(game.Players:GetPlayers()) do
if player ~= nil then
local stats = player:FindFirstChild("leaderstats")
local cash = stats:FindFirstChild("Coins")
local amount = 200
cash.Value = cash.Value + amount
local title = "Payout!🤑"
local text = "You have recived "..amount.." Coins!🤑"
local image = ""
SyncAPI(title,text,image,player)
end
end
end
FireAllClients fires to every player
Ok so this is my new code yet it still won’t fire I don’t know if the local script needs to be edited.
Serverscript:
local PlayerService = game:GetService("Players")
local CoinNotify = game.ReplicatedStorage.CoinNotify
local Player = PlayerService:GetPlayers()
local function SyncAPI(what, what2, what3, Player)
CoinNotify:FireClient(Player, PlayerService)
end
while true do
wait(2)
for _,player in pairs(game.Players:GetPlayers()) do
if player ~= nil then
local stats = player:FindFirstChild("leaderstats")
local cash = stats:FindFirstChild("Coins")
local amount = 200
cash.Value = cash.Value + amount
local title = "Payout!🤑"
local text = "You have recived "..amount.." Coins!🤑"
local image = ""
SyncAPI(title,text,image,player)
end
end
end
Local Script:
game.ReplicatedStorage.CoinNotify.OnClientEvent:Connect(function(CustomTitle,CustomText,CustomImage,player)
game.StarterGui:SetCore('SendNotification', {
Title = CustomTitle,
Text = CustomText,
Icon = CustomImage,
Duration = 5
})
end)
you also need to provide the values
CoinNotify:FireClient(Player, what, what2, what3)
It worked great! Thanks for the help, really appreciated!
1 Like