So, I have 8 seats inside a folder in workspace, and basically what I am trying to do is that if 8 players are sitting on these seats (not just 1 or 2 seats, all of the seats need to have someone sitting in them) at the same time, then something will happen, and this something will spawn a part (coin) from replicatedstorage as well as change the skybox (send it from replicatedstorage to lighting)
And after a player collects the coin (only 1 player can get it), so once someone touches it, that someone gets a badge and the coin despawns and no one else can collect it unless 8 players sit on all 8 seats at the same time again.
I’m unsure how to work with this but this is what I have so far: (I’m stuck on trying to figure out how to make it so that if 8 players are seated it works, I know using touched event is wrong but that’s were I started from and not sure where to go after from there):
Main ServerScript under ServerScriptService:
local rs = game:GetService("ReplicatedStorage")
local coin = rs:WaitForChild("BlackCoin")
local remote = rs.Remotes.AwardBlackCoinBadge
local pos = game.Workspace:WaitForChild("BlackCoinTP")
local sound = game.Workspace.BlackCoinSound
local Folder = game.Workspace.Seats
local lighting = game.Lighting
local sky1 = rs.Sky
local atmosphere1 = rs.Atmosphere
local sky2 = rs.SkyDARK
local atmosphere2 = rs.AtmosphereDARK
local SeatsTable = {}
for i,v in pairs(Folder:GetChildren()) do
table.insert(SeatsTable, v)
end
for i,v in pairs(SeatsTable) do
v.Touched:Connect(function()
sound:Play()
sky2.Parent = lighting
atmosphere2.Parent = lighting
sky1.Parent = rs
atmosphere1.Parent = rs
coin.Parent = workspace
coin.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
remote:FireAllClients(game.Players:GetPlayerFromCharacter(part.Parent))
coin.Parent = rs
sky2.Parent = rs
atmosphere2.Parent = rs
sky1.Parent = lighting
atmosphere1.Parent = lighting
sound:Stop()
end
end)
end)
end
Another ServerScript under ServerScriptService (Handles the remoteevent for giving badge to the 1 player who claims coin before others):
game.ReplicatedStorage.BadgeAwarder2.OnServerEvent:Connect(function(Player, userID, badgeID)
game.BadgeService:AwardBadge(userID, badgeID)
end)
LocalScript under StarterPlayerScripts (Also handles remoteevent for giving badge):
local blackCoinRemote = game.ReplicatedStorage.Remotes.AwardBlackCoinBadge
blackCoinRemote.OnClientEvent:Connect(function(player)
if player == game.Players.LocalPlayer then
game.ReplicatedStorage.BadgeAwarder2:FireServer(player.UserId, 267475149527160)
end
end)