-
What do you want to achieve? Keep it simple and clear!
give leaderstat coins to everyone -
What is the issue? Include screenshots / videos if possible!
instead of giving the coins out evenly it gives it to only one player (No Errors) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Devfourms, and youtube videos (even the shorts )
Code:
--Important VARs
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
--DataStore VARs
local FloorDataStore = DataStoreService:GetDataStore("PlayerFloors")
--Floor VARs
local FloorFolder = ServerStorage.Floors
--Elevator VARs
local Elevator = workspace.Elevator
local ElevatorSpawnPart = Elevator:FindFirstChild("SpawnPart")
local ElevatorDoorA = Elevator:FindFirstChild("DoorA")
local ElevatorDoorB = Elevator:FindFirstChild("DoorB")
local ElevatorBarrier = Elevator:FindFirstChild("Barrier")
local ElevatorPanel = Elevator:FindFirstChild("Panel")
local PanelTimer = ElevatorPanel.Screen.TimerGUI.TextLabel
--Sound VARs
local ElevatorMusic = ElevatorPanel.Screen.Music
local PlaySongEvent = ReplicatedStorage.Remotes.PlaySong
local MusicName = ReplicatedStorage.MusicName
local PanelDing = ElevatorPanel.Screen.Ding
local MusicPlaylist = script.ElevatorMusic:GetChildren()
local PlayerDataFolder = ReplicatedStorage.PlayerData
--Gameloop VARs
local IntermissionTime = 18
local DoorOpenTime = 3
local FloorLoop = math.random(1, #FloorFolder:GetChildren())
local SongLoop = math.random(1, #MusicPlaylist)
local player = nil
game:GetService("Players").PlayerAdded:Connect(function(Player)
player = Player
end)
local function OpenDoors()
ElevatorBarrier.SFX:Play()
while ElevatorDoorA.Position.Z <= 6 do
ElevatorDoorA.Position += Vector3.new(0, 0, 0.1)
ElevatorDoorB.Position -= Vector3.new(0, 0, 0.1)
wait()
end
end
local function CloseDoors()
ElevatorBarrier.SFX:Play()
ElevatorBarrier.CanCollide = true
while ElevatorDoorA.Position.Z >= 2 do
ElevatorDoorA.Position -= Vector3.new(0, 0, 0.1)
ElevatorDoorB.Position += Vector3.new(0, 0, 0.1)
wait()
end
end
--Gameloop functions
local function ElevatorTimer(tickValue)
for i=0, tickValue do
PanelTimer.Text = tickValue - i
wait(1)
end
end
local function Intermission()
--Play some tunes
if SongLoop == #MusicPlaylist then
SongLoop = 1
else
SongLoop +=1
end
if ElevatorMusic.TimeLength ~= 0 then
--warn("Musics TimeLength = 0. " ..MusicName.Value)
ElevatorMusic.SoundId = MusicPlaylist[SongLoop].SoundId
ElevatorMusic.Volume = MusicPlaylist[SongLoop].Volume
ElevatorMusic:Play()
MusicName.Value = MusicPlaylist[SongLoop].Name
print("Now Playing: " .. MusicPlaylist[SongLoop].Name)
else
warn("Musics TimeLength = 0")
end
--Wait until timer is up
ElevatorTimer(IntermissionTime)
MusicName.Value = "Nothing"
ElevatorMusic:Stop()
PanelDing:Play()
end
local BackupSkyboxDebounce = false
function BackupSkybox()
if BackupSkyboxDebounce == false then
BackupSkyboxDebounce = true
warn("SkyBox Not Found. Creating Backup...")
local backupSkybox = script.SkyboxBackup:FindFirstChild("Skybox"):Clone()
backupSkybox.Parent = Lighting
task.wait(5)
BackupSkyboxDebounce = false
end
end
local function ClearFloor()
for i, child in ipairs(Lighting:GetChildren()) do
if child.ClassName == "Sky" then
if script:FindFirstChild("Skybox") then
script:FindFirstChild("Skybox").Parent = Lighting
else
BackupSkybox()
end
end
child:Destroy()
end
if workspace:FindFirstChild("CurrentFloor") then
workspace:FindFirstChild("CurrentFloor"):Destroy()
else
warn("Could Not Destroy CurrentFloor")
end
for i, child in ipairs(PlayerDataFolder:GetChildren()) do
if child.InElevator.Value == true then
PlaySongEvent:FireClient(Players:FindFirstChild(child.Name), 0)
if player ~= nil then
--print("passing coins")
player.leaderstats.Coins.Value += 6
local newSound = script.Pickup:Clone()
newSound.Parent = player.Character:FindFirstChild("HumanoidRootPart")
newSound:Play()
newSound.Ended:Wait()
newSound:Destroy()
--print("passed giving coins")
end
end
end
print("Giving Back NPCS")
if ReplicatedStorage.StoredNPCS:FindFirstChild("NPCS") then
ReplicatedStorage.StoredNPCS:FindFirstChild("NPCS").Parent = workspace
end
-- Give Coints
end
local function NewFloor(floorId)
local floor = floorId:Clone()
floor.Name = "CurrentFloor"
if floor:FindFirstChild("Dangerous") then
local floorDangerous = floor:FindFirstChild("Dangerous")
if floorDangerous.Value == true then
print("Dangerous Floor")
task.wait(1)
workspace.NPCS.Parent = ReplicatedStorage.StoredNPCS
else
print("Non Dangerous Floor")
end
end
-- for all children in lighting folder
for i, child in ipairs(floor.LightingEffects:GetChildren()) do
if child.ClassName == "Sky" then -- if class is a sky then
if Lighting:FindFirstChild("Skybox") then -- if we find a name with "skybox"
Lighting:FindFirstChild("Skybox").Parent = script
else
BackupSkybox()
end
child.Parent = Lighting
end
end
floor.Parent = workspace
if floor.OpenBarrier.Value then
ElevatorBarrier.CanCollide = false
end
--Play Floor music, if any
if floor:FindFirstChild("Music") then
for i, child in ipairs(PlayerDataFolder:GetChildren()) do
if child.InElevator.Value then
PlaySongEvent:FireClient(Players:FindFirstChild(child.Name), floor.Music.Value, floor.Music:GetAttribute("Looped"), floor.Music:GetAttribute("StartPos"), floor.Music:GetAttribute("Volume"))
end
end
MusicName.Value = floor.Music:GetAttribute("SongName")
end
--Add Floor for Players
for i, child in ipairs(PlayerDataFolder:GetChildren()) do
if child.InElevator.Value then
child.TotalFloors.Value += 1
end
end
end
local function CollectPlayers()
for i, child in ipairs(Players:GetChildren()) do
if child.Character:FindFirstChild("HumanoidRootPart") and PlayerDataFolder:FindFirstChild(child.Name).InElevator.Value then
child.Character:FindFirstChild("HumanoidRootPart").CFrame = ElevatorSpawnPart.CFrame
end
end
end
--Other stuff
Players.PlayerAdded:Connect(function(player)
--Create new Player profile
local newProfile = script.ProfileTemplate:Clone()
newProfile.Name = player.Name
newProfile.Value = player.UserId
newProfile.Parent = PlayerDataFolder
end)
Players.PlayerRemoving:Connect(function(player)
local playerProfile = PlayerDataFolder:FindFirstChild(player.Name)
--Save Player data
if playerProfile then
--Save Player data
FloorDataStore:SetAsync(player.UserId, playerProfile.TotalFloors.Value)
--Remove Player profile
playerProfile:Destroy()
end
end)
while true do
--Elevator loop
local ElevatorTeam = game:GetService("Teams").Elevator
repeat
wait()
if #ElevatorTeam:GetPlayers() ~= 0 then
-- yes players in elevator
Intermission()
else
-- no players in elevator
--print("no players on team")
end
until #ElevatorTeam:GetPlayers() ~= 0
if FloorLoop == #FloorFolder:GetChildren() then
FloorLoop = 1
else
FloorLoop +=1
end
NewFloor(FloorFolder:GetChildren()[FloorLoop])
--NewFloor(FloorFolder.Mansion)
if workspace.CurrentFloor.OpenDoor.Value then OpenDoors() end
ElevatorTimer(workspace:FindFirstChild("CurrentFloor").FloorTime.Value)
if workspace.CurrentFloor.OpenBarrier.Value == true then
CollectPlayers()
end
if workspace.CurrentFloor.OpenDoor.Value == true then CloseDoors() end
ClearFloor()
end
Main Lines:
game:GetService(“Players”).PlayerAdded:Connect(function(Player)
player = Player
end)
&
for i, child in ipairs(PlayerDataFolder:GetChildren()) do
if child.InElevator.Value == true then
PlaySongEvent:FireClient(Players:FindFirstChild(child.Name), 0)
if player ~= nil then
--print("passing coins")
player.leaderstats.Coins.Value += 6