Help with :ClearAllChildren() and RemoteEvents

Hello! I’m not an advanced scripter or anything and I’m not that experienced with RemoteEvents.

I am attempting to make some sort of placing system. For this part however, the game detects when a user presses R on their keyboard to then send a RemoteEvent. A server script then detects this and (here’s where it all goes wrong:) is meant to :ClearAllChildren() of a specific folder found in Workspace. (So when the user wishes to clear all the traffic cones they’ve placed, they press R and they all get deleted)

LocalScript code:

local UIS = game:GetService("UserInputService")
local Tool = script.Parent

Tool.Activated:Connect(function()
	UIS.InputBegan:Connect(function(input)
		if input == Enum.KeyCode.R then
			game.ReplicatedStorage.ClearCone:FireServer()
		end
	end)
end)

ServerScript code:

game.ReplicatedStorage.ClearCone.OnServerEvent:Connect(function()
	game.Workspace.PlacedCones:ClearAllChildren()
end)

Just to be clear, here are the order of events: (1 and 2 do not apply for now)

  1. User equips the tool.
  2. User clicks to place cones.
  3. If the user wants to delete the cones, they equip the tool and then press R. (when the RemoteEvent is fired)
  4. The cones are deleted. (when the RemoteEvent is fired)

I would very much appreciate any help! Additionally, if you would like to give me any feedback on this post or my code please do so as I am always looking to improve.

:warning: There are no errors in the output too! :warning:

I’m not sure I understand what the problem is. Is the server not clearing the cones when the player presses R?
Are you firing a remote to place a cone? If not, all the cones are going to be created on the client. No cones will be deleted because the server doesn’t think any exist.

Oh sorry I completely forgot to mention that. Yes, it’s not deleting the cones inside of the “PlacedCones” folder. The cones are all cloned from ReplicatedStorage in a Server Script into the “PlacedCones” folder inside of Workspace. Sorry for the confusion and I appreciate your reply!

Ah, I missed this.

Try if input.KeyCode == Enum.KeyCode.R then

Works absolutely perfectly. I apologise for making such a silly mistake. Thanks so much. :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.