Why does the sound randomly go off

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    A King Of The Hill that actually works

  2. What is the issue?
    The sound randomly goes off

  3. What solutions have you tried so far?
    Finding a solution

PlayersInHill = {}

script.Parent.Touched:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then
			Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if #PlayersInHill == 0 then
				table.insert(PlayersInHill, Player)
			else
				for i,v in pairs(PlayersInHill) do
					if v.Name ~= Player.Name then
						table.insert(PlayersInHill, Player)
					end
				end
			end
		end
	end
end)

script.Parent.TouchEnded:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		for i,v in pairs(PlayersInHill) do
			if v.Name == Player.Name then
				table.remove(PlayersInHill,i)
			end
		end
	end
end)
local debounce = false

while wait(5) do
	if #PlayersInHill > 0 then
		for i,v in pairs(PlayersInHill) do
			if debounce == false then
				debounce = true
				script.Parent.CoinSound:Play()
				v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 10000
				v.leaderstats.Diamonds.Value = v.leaderstats.Diamonds.Value + 100
				debounce = false
			end
		end
	end
end

Play around with the properties of the sound instance itself.

Add a print to both the .Touched and the .TouchEnded function, and just tell us what the output is (maybe you could print the Hit.Name as well).

image

Use this and tell us the output perhaps?

PlayersInHill = {}

script.Parent.Touched:connect(function(Hit)
    print(Hit.Name.."touch begin")
	if Hit.Parent:FindFirstChild("Humanoid") then
		if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then
			Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if #PlayersInHill == 0 then
				table.insert(PlayersInHill, Player)
			else
				for i,v in pairs(PlayersInHill) do
					if v.Name ~= Player.Name then
						table.insert(PlayersInHill, Player)
					end
				end
			end
		end
	end
end)

script.Parent.TouchEnded:connect(function(Hit)
    print(Hit.Name.."touch end")
	if Hit.Parent:FindFirstChild("Humanoid") then
		Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		for i,v in pairs(PlayersInHill) do
			if v.Name == Player.Name then
				table.remove(PlayersInHill,i)
			end
		end
	end
end)
local debounce = false

while wait(5) do
	if #PlayersInHill > 0 then
    print(PlayersInHill)
		for i,v in pairs(PlayersInHill) do
			if debounce == false then
				debounce = true
				script.Parent.CoinSound:Play()
				v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 10000
				v.leaderstats.Diamonds.Value = v.leaderstats.Diamonds.Value + 100
				debounce = false
			end
		end
	end
end

image

Try this one: since the script only plays the sound when a player is on the hill, it should tell you when its playing, and what has caused it to play. Apologies for making you do this so much.

PlayersInHill = {}

script.Parent.Touched:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then
			Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if #PlayersInHill == 0 then
				table.insert(PlayersInHill, Player)
			else
				for i,v in pairs(PlayersInHill) do
					if v.Name ~= Player.Name then
						table.insert(PlayersInHill, Player)
					end
				end
			end
		end
	end
end)

script.Parent.TouchEnded:connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		for i,v in pairs(PlayersInHill) do
			if v.Name == Player.Name then
				table.remove(PlayersInHill,i)
			end
		end
	end
end)
local debounce = false

while wait(5) do
	if #PlayersInHill > 0 then
	print(PlayersInHill)
		for i,v in pairs(PlayersInHill) do
			if debounce == false then
				debounce = true
				script.Parent.CoinSound:Play()
				print("sound playing thanks to "..v.Name)
				v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + 10000
				v.leaderstats.Diamonds.Value = v.leaderstats.Diamonds.Value + 100
				debounce = false
			end
		end
	end
end

Line 43 error " attempt to concatenate string with Instance"

I edited the code again, try with the new one (the post you just copied from).

The sound still doesn’t play randomly, it randomly stops for a bit

Nothing in output? If not, this would mean the script isn’t getting to that part of code.

image

Where is the Sound Instance located?

Sorry I don’t get what you mean

Where in the Explorer is CoinSound located?

image

Show the properties of CoinSound?

image

image

Set RollOffMaxDistance to 10000? I’m running dry on ideas.

Ok it works but you have to keep moving on that part for it to work is there a way to stand still on the part and still get it to work