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?
COMMUNITY QUESTION
How Do I Give A Random Weapon To A Newly Joined Player in my Game?
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)
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.

2 comments
reppls
Thanks!