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

My gun distribution script of my game do not work and it doesn't give guns. How can i solve it?

I have a question since some time and is in this script:

game.Workspace.Lobby.LobbyFloor.CanCollide = false

wait(2)

**game.ReplicatedStorage.JetPack:Clone()

game.ReplicatedStorage.JetPack.Parent = game.Players.LocalPlayer.Backpack

game.ReplicatedStorage.HyperlaserGun:Clone()

game.ReplicatedStorage.HyperlaserGun.Parent = game.Players.LocalPlayer.Backpack**

When i want to give the guns to the users that play my game i write this to my scripting knowledge ('till i write this question) The game.ReplicatedStorage.HyperlaserGun:Clone() is for clone the gun to then move it to the player's backpack but that doesn't work for me.

Do you have any solution for this?

Thanks in advance.

2 answers

You didn't set a variable for the cloned Laser Gun.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

workspace.Lobby.LobbyFloor.CanCollide = false

wait(2)

for i,Player in pairs(Players:GetPlayers()) do
	local newJetpack = ReplicatedStorage.JetPack:Clone()

	newJetPack.Parent = Player.Backpack

	local newLaserGun = ReplicatedStorage.HyperlaserGun:Clone()

	newLaserGun.Parent = Player.Backpack
end

In the code above we have a loop that loops through all the players. We create two variables for each of our cloned items. Now we parent those into the Player's backpack. The loop we have above gets all of the players and repeats these instructions.

Hope this helped!

4 comments

0

unnecessary scripting

0

Your upvotes received is -12 lol

0

this code is eine.

0

ok thx because he thinks that this is "unnecessary"

you dont even need to do it like that guy answered, u can clone and parent a model at the same time, this would be the script

game.ReplicatedStorage.JetPack:Clone().Parent = game.Players.LocalPlayer.Backpack

game.ReplicatedStorage.HyperlaserGun:Clone().Parent = game.Players.LocalPlayer.Backpack

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