Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago

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!

0
unnecessary scripting Gameplayer365247v2 1055 — 5y
0
Your upvotes received is -12 lol Mr_Unlucky 1085 — 5y
0
this code is eine. User#24403 69 — 5y
0
ok thx because he thinks that this is "unnecessary" Mr_Unlucky 1085 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question