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

Why doesn't this work?

I have a script that clears all the children from workspace when someone presses "f". Can you help?

If you were going to ask, this IS in a local script.

local lclplr = game.Players.LocalPlayer
local Mouse = lclplr:GetMouse()

Mouse.KeyDown:connect(function(key)
	
	if key == "f" then
		game.Workspace:ClearAllChildren()
	
		end
end)

2 comments

1

Make sure the local script is in StarterGui or StarterPack; I just tested the script and it works.

0

+1

2 answers

There is Nothing wrong with your Script, Just that it must be in a Localscript, and placed in StarterGui or StarterPack.

if this Helped please accept answer and upvote!

If you want it to remove the children of Workspace, you probably should make it on Player entered using: game.Players.PlayerAdded:connect(function(Player) end)

And plus, I don't know if this is part of the error, but the if Key == "f" then should probably be if Key:lower() == "f" then

And use this in a regular script.

game.Players.PlayerAdded:connect(function(Player)
	Player:GetMouse().KeyDown:connect(function(Key)
		if Key:lower() == "f" then
			game.Workspace:ClearAllChildren()
		end
	end)
end)

2 comments

0

doesn't matter if you use the "lower()"

0

You can't getmouse in a server script.

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