So I have a Local Script put into StarterCharacterScripts that is supposed to play a specific song when the play touches a part and when the player touches another part the first song stops and a new one plays and the player is teleported to another level. This works but it works for the whole server. What I mean is: when Player 1 and 2 load in the first level song starts to play. But, when Player 1 does the level and touches the teleport block the first song stops and the second songs plays for both Player 1 and 2, despite Player 2 never even going on the level. Maybe something to do with Localization errors on my end? Not sure. I've placed my script for the Local Script below and my leaderstats script since it establishes something used for the local script (starred the part that is used).
Local Script
-- Flag Variables
local playingTF = false
local playingDM = false
local player = game.Players.LocalPlayer
local musicFolder = player:WaitForChild("Music")
local function musicPlayerTF(player)
print("Called.")
-- Player Variables
local character = player.Parent
local humanoid = character:FindFirstChild("Humanoid")
local RSService = game:GetService("ReplicatedStorage")
if humanoid then
print("Human detection.")
if not playingTF then
musicFolder["Forest Music"]:Play()
playingTF = true
print("Function success.")
else
print("Music not repeated/played.")
end
end
end
local function musicplayerDM(player)
print("Called.")
-- Player Variables
local character = player.Parent
local humanoid = character:FindFirstChild("Humanoid")
local RSService = game:GetService("ReplicatedStorage")
if humanoid then
print("Human detectoin.")
if not playingDM then
musicFolder["Forest Music"]:Stop()
print("Music stop.")
musicFolder["Death Mountain"]:Play()
playingDM = true
else
print("Music not stopped.")
end
end
end
game.Workspace.Checkpoints.Lobby.Touched:Connect(musicPlayerTF)
game.Workspace["Titan Forest"].Teleporter["Forest Teleport"].Touched:Connect(musicplayerDM)
Leaderstats Script
local dataStore = game:GetService("DataStoreService")
local currencyStore = dataStore:GetDataStore("currencyStore")
game.Players.PlayerAdded:Connect(function(player)
-- Creating leaderstat sections.
local leaderboard = Instance.new("Folder", player)
leaderboard.Name = "leaderstats"
local deaths = Instance.new("IntValue", leaderboard)
deaths.Name = "Deaths"
local ltimeCount = Instance.new("IntValue", leaderboard)
ltimeCount.Name = "Level Time"
local timeCount = Instance.new("IntValue", leaderboard)
timeCount.Name = "Total Time"
local nonLeaderboard = Instance.new("Folder", player)
nonLeaderboard.Name = "leaderstats_ns"
local currency = Instance.new("IntValue", nonLeaderboard)
currency.Name = "Coins"
local leveltimeStart = Instance.new("BoolValue", nonLeaderboard)
leveltimeStart.Name = "Level Time Start"
leveltimeStart.Value = false
local leveltimeController = Instance.new("BoolValue", nonLeaderboard)
leveltimeController.Name = "Level Time Control"
leveltimeController.Value = true
local currencyGiven = Instance.new("BoolValue", nonLeaderboard)
currencyGiven.Name = "Currency Given"
currencyGiven.Value = false
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
deaths.Value += 1
end)
end)
while wait(1) do
timeCount.Value += 1
end
end)
**game.Players.PlayerAdded:Connect(function(player)
local RSService = game:GetService("ReplicatedStorage")
local musicFolder = RSService.Music:Clone()
musicFolder.Parent = player
end)**
** You are now Level 2! **