How to obtain Tools via a LocalScript?

Hello, I am trying to make a fps game and I want to make it where whenever you spawn, you spawn with the guns/tools. The local script is located in StarterPlayer.StarterPlayerScripts and I have already tried using a normal script in ServerScriptService with no changes to the code. Basically, the script runs when the player is added. It checks a folder in ReplicatedStorage with tools using GetChildren: and detects if the child is a Tool. If it detects a tool, it should take that tool, clone it, and make its parent the players’ backpack. But it doesn’t work. No errors in output, nothing.

Here’s the script:

local StarterPack = true --If true, player will spawn with the tools located in game.ReplicatedStorage.SAE["SAE - Tools"]

game.Players.PlayerAdded:Connect(function(Player)
	if StarterPack == true then
		for i, v in game.ReplicatedStorage.SAE["SAE - Tools"]:GetChildren() do
			if v:IsA("Tool") then
				v:Clone().Parent = Player.Backpack
			end
		end
	end	
end)

I’d appreciate some help.

Let’s first debug. Add prints in all the execution places and see what prints.

1 Like

Like this?

Yes.

Huh…


Just “1”.

I think it may be the function, idk.

Try in a live server. PlayerAdded is known to sometimes not fire in studio due to many factors such as computer lag

Everytime the player spawns, fire a RemoteEvent from the client and give the player tools from the server.

Not efficient since exploiters can fire that remote and give themselves more tools than they should get

1 Like


Oof.

Ah I see, it’s a client script. Convert it to a server script.

It’s worth a shot. I’ll try to look for a way to prevent exploters from firing it again like some bool value.

I have already tried it but I’ll still check.

I don’t think that would work. I recommend doing it as a server script and move the tools inside ServerStorage, where no client can access.

You can use both PlayerAdded() and CharacterAdded() in Server and Client-Sided script. However, if you are listening to PlayerAdded() in LocalScript , it will only fire when another player joins, not when the player who runs the LocalScript joins . Which means the “2” will only be printed when someone else joins.

2 Likes

So it has to be a normal script in ServerScriptService to work?

The tools have to be put into the player backpack in server side only.

Yes, you can use a script from ServerScriptService, and use the function CharacterAdded, then clone the tools and place it in the player’s backpack.

Yes.

No, doing player added in client side never work for us (the client), it work only for the next players added after you joined the game, because all local script are starting to run only once your player object was already added.