Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Checkpoint dont work well (color and sound) can someone help me please?

Hey I am making a obby with checkpoints, the problem is, when someone touch the checkpoint, everybody hear the sound he made and everybody see the checkpoint turn to green, I have already tried to to put the two following scrippts in local script but its dont work. Theres the scripts: the sound script:

local part = script.Parent
local runnable = false
local player = game.Players.LocalPlayer

game.Players.ChildAdded:Connect(function(player)
	part.Touched:Connect(function(Hit)
		if not runnable then
			runnable = true
			if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
				local sound = script.Parent.Checkpoint

				if not sound.IsPlaying then
					sound:Play(player)
				end
			end
		end
	end)
end)

the color script:

local part = script.Parent
local player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(player)
	part.Touched:Connect(function(Hit)
		script.Parent.BrickColor = BrickColor.new("Lime green")
	end)
end)

and the checkpoint script (in serverscript services):

local checkpoints = workspace:WaitForChild("Checkpoints droite")
local remoteEvent = game.ReplicatedStorage:WaitForChild("ResetStatEvent") -- Again, you can use any name here

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = 0
	stage.Parent = leaderstats

	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(checkpoints[stage.Value].Position)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == stage.Value + 1 then
					stage.Value = stage.Value + 1
				end
			end
		end)
	end)
end)

-- Added code here
remoteEvent.OnServerEvent:Connect(function(plr)
	if plr and plr.Character and plr.Character:FindFirstChild("Humanoid") then
		local humanoid = plr.Character.Humanoid
		plr.leaderstats.Stage.Value = 0
		humanoid.Health = 0
	end
end)

Thanks you in advance!

1 answer

Assuming you know the basics of roblox studio, I can help you with your sound problem.

First you need to change the sound script to,

local part = script.Parent
local runnable = false
local player = game.Players.LocalPlayer

game.Players.ChildAdded:Connect(function(player)
	part.Touched:Connect(function(Hit)
		if not runnable then
			runnable = true
			if Hit.Parent:FindFirstChild("Humanoid") ~= nil then
				game.ReplicatedStorage.[RemoteEventName]:FireClient(player)
			end
		end
	end)
end)

And Create a remote event in replicated storage. (make sure to rename it whatever you call it in the script)

Then add a local script in StarterGUI then put

local SoundServices = game:GetService("SoundService")
local sound = script.Parent.Checkpoint

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)
	SoundServices:PlayLocalSound(sound)
end)

1 comment

0

Hey! TY for you answer! but its dont work a lot, in the output I have this error: "12:17:26.359 Checkpoint is not a valid member of PlayerGui "Players.wDaerkfeX.PlayerGui" thank you in advance!

This discussion is preserved as it was. New answers, comments, and votes are closed.