local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local greetPlayer = ReplicatedStorage.GreetPlayer
local announcement = ReplicatedStorage.Announcement
local giveCoins = ReplicatedStorage.GiveCoins
Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats" -- Changed to lowercase for Roblox leaderboard system
leaderstats.Parent = plr
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 50
coins.Parent = leaderstats
greetPlayer:FireClient(plr, "Hello! Welcome to the game! "..plr.Name)
task.wait(5)
greetPlayer:FireClient(plr, "Please join the group and like the game!")
end)
giveCoins.OnServerEvent:Connect(function(player, coinsamt)
local leaderstats = player:FindFirstChild("leaderstats") -- Changed to lowercase
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
print("button clicked, giving " .. tostring(coinsamt) .. " coins to " .. player.Name)
coins.Value = coins.Value + coinsamt
else
warn("Coins stat not found for player: " .. player.Name)
end
else
warn("leaderstats folder not found for player: " .. player.Name)
end
end)
task.wait(15)
announcement:FireAllClients() -- Corrected: FireAllClients is a method
local buyButtonFunction = game.ReplicatedStorage.BuyButton
buyButtonFunction.OnServerInvoke = function(plr)
local purchaseSuccessful = false
local leaderstats = plr.leaderstats
local coins = leaderstats.coins
if coins.value >= 50 then
coins.value -= 50
local purchaseSuccessful = true
end
end