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

I need help with my game script it wont clone the gun to the players backpack? [Unanswered]

Asked by
Prioxis 673 Moderation Voter
9 years ago

So I got a function and a for loop set up and everything but for some reason it just won't clone anything to anywhere

Here's my script

local mapDirectory = game.Lighting.Maps 
local RoundName = game.Lighting.RoundNames                              
while true do                           
local maps = mapDirectory:getChildren() 
local RoundNames = RoundName:getChildren()

if #maps == 0 then                      
    print("Maps not found! Selfremoving...") 
    script:remove()                     
    return                              
end                                     
h = Instance.new("Hint")                
timeMin = 5                             
timeSec = 0                             

function Countdown(min,sec,txt,pretxt)  
h.Parent = game.Workspace               
for i = 1, sec + (min * 60) + 1 do      
if sec < 10 and min == 0 then           
h.Text = pretxt.." 0:0"..sec.." "..txt  
elseif sec < 10 then                    
h.Text = pretxt.." "..min..":0"..sec.." "..txt
elseif sec + (min * 60) < 60 then       
h.Text = pretxt.." 0:"..sec.." "..txt   
elseif sec + (min * 60) > 59 then       
h.Text = pretxt.." "..min..":"..sec.." "..txt
end                                     
wait(1)                                 
if sec > 0 then                         
sec = sec - 1                           
elseif sec == 0 and min ~= 0 then       
sec = 59                                
min = min - 1                           
elseif sec == 0 and min == 0 then       
print("Ended")                          
end                                     
end                                     
h.Parent = nil                          
end                                     
pretext = "Time untill the next round..." 
local pickedRoundName = "Team Deathmatch"
text = "Round Chosen..." ..pickedRoundName.." have fun!"        
h:remove()                  
msg = Instance.new("Hint")              
msg.Parent = workspace                  
msg.Text = "Sorry for any errors"       
wait(0)                                 
msg.Text = "...Choosing a new map..."   
wait(1)                                 
local pickedMap = maps[math.random(1, #maps)] 
local pickedMapClone = pickedMap:clone()
pickedMapClone.Parent = game.Workspace  
pickedMapClone:makeJoints()             
wait(2.5)                               
msg.Text = "Map chosen is: " ..pickedMapClone.Name.."."     
wait(2)                                 
msg.Text = "Kill everybody at..." ..pickedMapClone.Name.." to survive."  
wait(2)                                 
msg:remove()                            



local pplz = game.Players:GetChildren() 
local team1 = CFrame.new(100, 11.5, -69.5)
local team2 = CFrame.new(-186, 11.5, 106.5)

function GiveWep()
    local a = game.Lighting.Gun:Clone()
    a.Parent = pplz.Backpack 
end

for i = 1,#pplz do                      
if pplz[i].TeamColor == BrickColor.new("Bright red") and pplz[i] ~= nil and pplz[i].Character:FindFirstChild("Torso") ~= nil then-- change to team1's TeamColor--SCRIPTED BY CLIMAXIMUS                     
pplz[i].Character.Torso.CFrame = CFrame.new(100, 12.5, -69.5) 

elseif pplz[i].TeamColor == BrickColor.new("Bright blue") and  pplz[i] ~= nil and pplz[i].Character:FindFirstChild("Torso") ~= nil then--change to team2's TeamColor--SCRIPTED BY CLIMAXIMUS
pplz[i].Character.Torso.CFrame = CFrame.new( -186, 11.5, 106.5)

for i = 1,#pplz do 
    local a = game.Lighting.Gun:Clone()
    a.Parent = pplz.Backpack 
end

end end                                 
print("Map inserted: " .. pickedMap.Name) 
Countdown(timeMin,timeSec,text,pretext)
pickedMapClone:remove()             

wait(1)                         

local pplz = game.Players:GetChildren()
local lobby = CFrame.new(-130.55, 148.67, -11.9)
for i = 1,#pplz do                      
if pplz[i] ~= nil and pplz[i].Character:FindFirstChild("Torso") ~= nil then 

pplz[i].Character.Torso.CFrame = lobby  
end                                     
end                                     
end                                                     

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

On line 79, you can replace line 79 to line 82 with

game.Lighting.Gun:clone().Parent = pplz[i].Backpack
0
Thanks man! it works :D Prioxis 673 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

At the GiveWep() function, you forgot to clone the gun to the player's backpack, instead you just cloned it to the player.

function GiveWep()
    local a = game.Lighting.Gun:Clone()
    a.Parent = pplz[i].Backpack --This!
end
0
it doesn't work it just says Error without explaining what the error is Prioxis 673 — 9y

Answer this question