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

Won't delete nor clone?

Okay so I have a well, let me show you script..


local Banned = game.Workspace.Banned.Value
local p = game.Players.LocalPlayer
function Banned()
	if p.Name == Banned then
    local Ban = game.ServerStorage.BanCode:Clone()
    p.Backpack.Switch:Destroy()
    p.Backpack.dETONATE:Destroy()
    p.Backpack["sPEED UP"]:Destroy()
    p.Backpack["Slow down"]:Destroy()
	Ban.Parent = p.Backpack
	end
end
game.Players.PlayerAdded:connect(Banned)

It won't remove the stuff or the clone After solved I will ask another for my BanCode script

3 answers

Is this in a LocalScript or a normal Script? If it's a LocalScript, your problem is-

game.Players.PlayerAdded:connect(Banned)

If it's a Script, your problem is-

local p = game.Players.LocalPlayer

3 comments

0

I changed it to script, removed localplayer and added p in function, still does nothing

0

You're checking if the player's name is equal to Banned?

0

Yes

You've overridden the variable "Banned" with a function. Differ the Names between the function Banned() and the StringValue

local Bannedlist = game.Workspace.Banned.Value
local p = game.Players.LocalPlayer
function Banned()
    if p.Name == Bannedlist then
    local Ban = game.ServerStorage.BanCode:Clone()
    p.Backpack.Switch:Destroy()
    p.Backpack.dETONATE:Destroy()
    p.Backpack["sPEED UP"]:Destroy()
    p.Backpack["Slow down"]:Destroy()
    Ban.Parent = p.Backpack
    end
end
game.Players.PlayerAdded:connect(Banned)



3 comments

0

K

0

It still won't work?

0

I'm out for ideas then:/

Make sure you're checking if the Backpack has those items, before calling Destroy on them.

For example, you should be at the least be doing:

if p.Backpack:FindFirstChild(Switch) then
	p.Backpack:FindFirstChild(Switch):Destroy()
end

Another improvement maybe on your bannedlist, for as it stands now you can only ban one player.

I would have a check like this done:

Bannedlist = ","..Bannedlist..","
if string.find(Bannedlist,","..p.Name..",") then
-- you code
end

I add these commas just to ensure that you're not punishing someone who's name is ABC123, when you've actually banned ABC1234 - the string.find will still say it sees ABC123 in the list, so by adding a comma to the beginning and end, string.find can reliably look for an exact match.

Just a suggestion... Plus I'm not sure about adding the ban code to the Backpack - I would probably parent it to the player Character object instead, but if that works - great.

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