This script is for a clean workspace GUI. Click Here to see the game When you click clean workspace it will delete you(the player) but I want to prevent that. But I don't know how to prevent that. I will deeply appreciate your help.
function onClick() local workspaceChildren = game.Workspace:GetChildren() wait(3) for i = 1, #workspaceChildren do if workspaceChildren[i].className == "Model" then workspaceChildren[i]:Remove() end end end script.Parent.MouseButton1Click:Connect(onClick)
You can use GetPlayerFromCharacter
to check whether or not the model is associated with a Player
object:
local Players = game:GetService('Players'); script.Parent.MouseButton1Click:Connect(function() local workspaceChildren = game.Workspace:GetChildren() wait(3) for i = 1, #workspaceChildren do local child = workspaceChildren[i]; if child.ClassName == "Model" and not Players:GetPlayerFromCharacter(child) then child:Destroy() end end end)
Hope this helped. Read more about anonymous functions.
PS: className
and Remove
are deprecated; use ClassName
and Destroy
instead.