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

A script that only lets certain people spawn with tools?

Hi, I'm a novice in scripting, and I am in need of help qq

Right now I am trying to create a script that would only allow certain players in the said script to spawn with these set of tools, so far this is what I got:

if game.Players.LocalPlayer.Name == "kevincatssing" then
	game.ServerStorage:GetChildren()
	for i, v in pairs(x) do
	v:Clone().Parent = game.Players["kevincatssing"].Backpack
end
end

I am planning to place the script in StarterGui

Please aid qq

1 answer

✓ Accepted answer

I'm assuming that you are using a LocalScript, because you are accessing the LocalPlayer. The first Thing I see that is Incorrect is that you are accessing the ServerStorage through a localscript, and a localscript can Never access the ServerStorage, use the ReplicatedStorage instead, you also didn't define what x is on line 03, Now lets fix your script.

admin={"kevincatssing"}

game.Players.ChildAdded:connect(function(player) -- I'm using the ChildAdded instead of PlayerAdded, because PlayerAdded doesn't work with a localscript
	if player.Name==admin[1] then
		local storage=game.ReplicatedStorage:GetChildren()
		for _,value in pairs(storage) do
			if value:IsA("Tool")  or value:IsA("HopperBin") then -- use the or
				value:Clone().Parent=player:FindFirstChild("Backpack")
			end
		end
	end
end)

15 comments

0

you are comparing the player's "name" to table "admin"

0

fixed.

0

Alright, I will try this now, thank you :D and for multiple 'admin', I just have to {"Name1", "Name2"}?

0

If this helped do mind accepting Answer. Thanks!

0

I will :D! And, in ReplicatedStorage, there is also other things besides the tools that I am placing in there, how do I make it so that it will only clone the Tools (Which consist of HopperBin and Tool, in their ClassName) only?

0

??

0

Clone tools only?

0

Yes, only the Tools, which consist of HopperBin and Tool, because there is also a few scripts in there that I don't want to copy over to the user's Backpack

0

I edited my answer.

0

Oh, so, on line 7, I just need to add a value for HopperBin too, besides the Tool? if value:IsA("Too", "HopperBin") then?? QQ

0

No no...I'll edit my answer.

0

Thank you so much :D

0

np.

0

Ahh... Thanks for the downvote, and I was told that A localscript can't access a ServerStorage, People aren't always correct.

0

I'm stupid, sorry. You're right.

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