local plr = game.Players.LocalPlayer
local partiwanttodestroy = script.Parent
while wait(0.1) do
if plr:FindFirstChild("test").BoolValue.Value == true then
partiwanttodestroy:Destroy()
end
end
but for some reason it doesn’t work, could yall help?
This seems to be a LocalScript since you’re using LocalPlayer. You can’t use a LocalScript in the Workspace.
Either move the LocalScript to somewhere that runs LocalScripts (StarterPlayerScripts, StarterGui, etc.) or make the LocalScript into a Script and adapt it so it doesn’t use LocalPlayer.
local plr = game.Players.LocalPlayer
local partiwanttodestroy = game.Workspace.Ok
while wait(0.1) do
if plr:FindFirstChild("test").BoolValue.Value == true then
partiwanttodestroy:Destroy()
end
end
but i get "Ok is not a valid member of Workspace “Workspace” in the output.
Since LocalScripts load on the client, you have to wait for things to load in on the client. Think about whenever you join a game with a lot of parts, sometimes you’ll notice that the assets don’t all load in until later! That’s what’s happening here.
To fix this, wait for part “Ok” to load in using WaitForChild:
local plr = game.Players.LocalPlayer
local partiwanttodestroy = game.Workspace:WaitForChild("Ok")
while wait(0.1) do
if plr:FindFirstChild("test").BoolValue.Value == true then
partiwanttodestroy:Destroy()
end
end