How can I fix Walls not destroying?

Hello everyone! Today I was making this duels system for my game. Everything works except for the walls destroying. I know the issue is that the remote event is firing twice on the server. But the issue is I don’t know how to fix it. I’ve tried destroying it client side but still. Nothing works! This is my local script which fires the remote event(it fires it twice because theres 2 players.)

while wait() do
	if VotesValue.Value == 2 then
		Button.Visible = false
		game.ReplicatedStorage.RemoteEvents.StartRoundEvent:FireServer(VotesValue.Value)
		local FindMap = workspace:FindFirstChild(Player.GameStats.MapChosen.Value)

		break
	end

This is the line in the server script that’s supposed to destroy the walls.

FindChosenMap.Walls:Destroy()

This is FindChosenMap is equal to.

local FindChosenMap = workspace:FindFirstChild(MapChosen.Value)

This is the error the console gets:
image
If you’d like the full script then say below! Any help is apreciated!

Thank you.

Instead of an infinite loop, you should connect to an event, like perhaps when the Votes value changes. That way you can be sure to only Fire the remote once for that player. You can also set up a debounce on the server so that if the remote is fired multiple times, as in once for each player, you can make sure it only runs once at a time. A debounce is simply checking if a variable is true or false at any given time. if its false, you can set it to true, wait some time, then set it to false again.

Also the reason for the error is because you aren’t checking if Walls exist before attempting to reference/destroy it. You are only checking if the Map exists.

1 Like

To fix the error you can just do

local FindChosenMap = workspace:FindFirstChild(MapChosen.Value)
if FindChosenMap  then
FindChosenMap.Walls:Destroy()
else
return
end

Now that will work, but keep in mind that if that remote can fire the round to start, you should remove it entirely and make it server sided.

It is serversided. But I’ll try this thank you.

Ok I did something what you said to do. But it prints but still doesn’t destroy. This is the new code that removes the wall.

if FindChosenMap:FindFirstChild("Walls") then
				print("WALLSLSLSL")
				FindChosenMap.Walls:Destroy()
			end

Here is is printing the print thing
image

if FindChosenMap:FindFirstChild(“Walls”) then
print(“WALLSLSLSL”)
FindChosenMap:WaitForChild(“Walls”):Destroy()
end

Try This For .OnServerEvent()

print(MapChosen)

1 Like

Didn’t work. I think the script firing twice has something to do with it. Because sometimes the game glitches and doesn’t fire it for the other player. THATS when it works! I think i’ll have to make 2 scripts in order to fix this. I’ll keep you all updated.

Can U Send Me The .OnServerEvent() Script?

Here:

local IsPlaying = true
local RemovedWalls = game.ReplicatedStorage:WaitForChild("Values"):WaitForChild("RemovedWalls")
game.ReplicatedStorage.RemoteEvents.StartRoundEvent.OnServerEvent:Connect(function(Player, Votes)
	

	local StopWatch = Player.GameStats:WaitForChild("StopWatch")
	local MapChosen = Player.GameStats.MapChosen
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	local HRP = Character:WaitForChild("HumanoidRootPart")
	local FindChosenMap = workspace:FindFirstChild(MapChosen.Value)
	if FindChosenMap then
		if game.ReplicatedStorage.Values.VotesValue.Value >= 2 then
			if FindChosenMap:FindFirstChild("Walls") then
				FindChosenMap:WaitForChild("Walls"):Destroy()
			end
		
			game.ReplicatedStorage.RemoteEvents.StartCountDownEvent:FireAllClients("DONTOTNT")
			Humanoid.WalkSpeed = 0
			Humanoid.JumpPower = 0
			HRP.Position = FindChosenMap.SpawnLocation.Position
			FindChosenMap.EndPart.Touched:Connect(function()
				IsPlaying = false
			end)
			wait(3)
		
			Humanoid.WalkSpeed = 16
			Humanoid.JumpPower = 50
			local CurrentValue = 0
			while IsPlaying == true do
				CurrentValue += task.wait()
				StopWatch.Value = CurrentValue - CurrentValue % 0.001

			end
		
		end
	else
 print("Map not found.")
		end
	end)


The first script was the wrong script. Sorry about that.

lmk what it prints

local IsPlaying = true
local RemovedWalls = game.ReplicatedStorage:WaitForChild("Values"):WaitForChild("RemovedWalls")
game.ReplicatedStorage.RemoteEvents.StartRoundEvent.OnServerEvent:Connect(function(Player, Votes)


	local StopWatch = Player.GameStats:WaitForChild("StopWatch")
	local MapChosen = Player.GameStats.MapChosen
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	local HRP = Character:WaitForChild("HumanoidRootPart")
	local FindChosenMap = workspace:FindFirstChild(MapChosen.Value)
	print("MAP PICKED: "..FindChosenMap)
	if FindChosenMap then
		if game.ReplicatedStorage.Values.VotesValue.Value >= 2 then
			if FindChosenMap:WaitForChild("Walls") then
				FindChosenMap:WaitForChild("Walls"):Destroy()
			end

			game.ReplicatedStorage.RemoteEvents.StartCountDownEvent:FireAllClients("DONTOTNT")
			Humanoid.WalkSpeed = 0
			Humanoid.JumpPower = 0
			HRP.Position = FindChosenMap.SpawnLocation.Position
			FindChosenMap.EndPart.Touched:Connect(function()
				IsPlaying = false
			end)
			wait(3)

			Humanoid.WalkSpeed = 16
			Humanoid.JumpPower = 50
			local CurrentValue = 0
			while IsPlaying == true do
				CurrentValue += task.wait()
				StopWatch.Value = CurrentValue - CurrentValue % 0.001

			end

		end
	else
		print("Map not found.")
	end
end)

Nothing prints at all… :frowning:

This text will be blurred

hm

If U Have Discord Add Me RQ So We Dont Cladder This Comment Section

cornholio11111 | Scripter#6948

dont do this. if you are checking if something exists, FindFirstChild is the one to use. Also if it does find it, you do not need to then WaitForChild to destroy it because it found it which means it exists.

I hope you are not using this as a way to check if multple players add 1 to this, because the server will not see changes made from the client. You will have to have those clients FireServer to then have the server make those changes.

While loops shouldn’t be added to this. Try this:

VotesValue.Changed:Connect(function()
    if VotesValue.Value == 2 then
        Button.Visible = false
            game.ReplicatedStorage.RemoteEvents.StartRoundEvent:FireServer(VotesValue.Value)
        local FindMap = workspace:WaitForChild(Player.GameStats.MapChosen.Value)
    end
end)

Let me know if this doesn’t work as intended!

Share the entire local script, I see you’ve already shared the server script, will be helpful, thanks.

Sorry for the late responce. This is the full local script:

local Button = script.Parent
local VotesValue = game.ReplicatedStorage.Values.VotesValue
local DontBreak = "kiolsdjifds;jofsdf"
local Player = game.Players.LocalPlayer
local HasVoted = Player.GameStats.HasVoted
local RemoteEvent = game.ReplicatedStorage.RemoteEvents.CastPlayerVoteEvent
Button.MouseButton1Click:Connect(function()
	if HasVoted.Value == false then
		HasVoted.Value = true
		RemoteEvent:FireServer(Button)
	else 
		HasVoted.Value = false
		RemoteEvent:FireServer(Button)
	end
end)

VotesValue.Changed:Connect(function()
	Button.Text = "Start(" .. VotesValue.Value .. "/2)"
	if VotesValue.Value == 2 then
		Button.Visible = false

		game.ReplicatedStorage.RemoteEvents.StartRoundEvent:FireServer(VotesValue.Value)
			local FindMap = workspace:FindFirstChild(Player.GameStats.MapChosen.Value)

	end

end)

Is this fixed now? Going off of the other thread?

1 Like

Yep. Its fixed now. Thx for asking