My main objective is that i’m trying to make it so whenever a player touches a checkpoint, theres a sound, and only the player that touched the checkpoint heres the sound. I have my sound in StarterGui and I have my Checkpoint script in ServerScriptService, but for some reason the sound part of the script isn’t working. Please help.
Here is my script:
local Rs = game.ReplicatedStorage
local Event = Rs:WaitForChild(“Events”)
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Parent = Player
leaderstats.Name = “leaderstats”
local Stage = Instance.new("NumberValue")
Stage.Parent = leaderstats
Stage.Name = "Stage"
Stage.Value = 0
local CheckpointsFolder = game.Workspace:FindFirstChild("Checkpoints")
for i, Checkpoint in pairs(CheckpointsFolder:GetChildren()) do
Checkpoint.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local PlayerHit = game.Players:GetPlayerFromCharacter(Hit.Parent)
Checkpoint.Color = Color3.fromRGB(75, 151, 75)
Checkpoint.Material = Enum.Material.Neon
if PlayerHit.leaderstats:FindFirstChild("Stage").Value == Checkpoint.Name - 1 then
PlayerHit.leaderstats:FindFirstChild("Stage").Value = Checkpoint.Name
workspace.SoundFx.Success:Play()
Event.CheckPointEvent:FireClient(Player)
end
end
end)
Player.CharacterAdded:Connect(function(Character)
repeat
wait()
until Character:FindFirstChild("HumanoidRootPart") ~= nil
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
HumanoidRootPart.CFrame = CheckpointsFolder:FindFirstChild(Stage.Value).CFrame + Vector3.new(0, 2, 0)
end)
end
end)