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

How Do I Give A Random Weapon To A Newly Joined Player in my Game?

I'm having a hard time trying to find a script for giving random weapon to a newly joined player in a game. I would also want to ask on how to make the weapon that had been given to the newly joined player permanent?

2 answers

Well, first make a folder in ServerStorage that has the weapons in it Now, make a script in ServerScriptStorage with this code

math.randomseed(tick())
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function()
		local tools = game.ServerStorage["NAME OF FOLDER"]:GetChildren()
		local tool = tools[math.random(1, #tools)]:Clone()
		tool.Parent = plr.Character
	end)
end)

2 comments

0

reppls

0

Thanks!

First, you need a weapon. I'd suggest putting the Tool in the ReplicatedStorage, but that's just my personal choice (you can even keep it in Workspace, but you shouldn't). For example, let's say we have a pistol in ReplicatedStorage. After that's done, do the following:

local storage = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		local pistol = storage.Pistol
		pistol.Parent = plr.Character.Backpack
	end)
end)

The script has to be in a LocalScript. You can build on that script to make random weapons.

1 comment

0

Where do I put the Script in?

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