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

Fixing this script/making it "better"?

No errors, but the script will only remove/search for the 'Sword' from on players backpack rather than the whole servers not sure why.

	for i, v in pairs(game.Players:GetPlayers()) do
		if not v.Backpack:FindFirstChild("Sword") then
		else
			v.Backpack:FindFirstChild("Sword"):Destroy()
		wPlayer = game.Workspace:FindFirstChild(v.Name)
		if not wPlayer:FindFirstChild("Sword") then
		else
			wPlayer:FindFirstChild("Sword"):Destroy()
		end
	end
end

EDIT: The part where it searches in the player in workspace doesn't work.

wPlayer = game.Workspace:FindFirstChild(v.Name)
        if not wPlayer:FindFirstChild("Sword") then
        else
            wPlayer:FindFirstChild("Sword"):Destroy()

1 answer

✓ Accepted answer

Hm, hard to tell with all the spacing. I'll create a new one:

for i,v in pairs(game.Players:GetPlayers()) do
	if v.Backpack:findFirstChild("Sword") then
		v.Backpack.Sword:Destroy()
	end
	if v.Character:findFirstChild("Sword") then
		v.Character.Sword:Destroy()
	end
end

I noticed you looked in WOrkspace for the character, instead of player.Character

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