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

Item not being cloned properly?

I've been trying to get this script to work for over a day now and I'm not sure what's causing it not to work. What I'm trying to do is when the levels value in the leaderboard turns to 50 it will clone the gun into the backpack, and so far there are no errors in the output. It's located in workspace as a local script.

 local plr = game.Players.LocalPlayer
 local lvls = plr.leaderstats.Level.Value
local gun = game.ReplicatedStorage.RedHyperLaser
 local gunClone = gun:Clone()
local gunClone.Parent = game.ServerStorage

function clonePart()
	gun:Clone()
	gunClone.Parent = game.ServerStorage

end

clonePart()

if lvls == 50 then
	gunClone.Parent = game.Players.LocalPlayer.Backpack else
	print("Error")
	
end

4 comments

0

Also I was testing this with the ROBLOX play button in studio.

0

Your going to have to make a while true do wait() end on 14 - 20, and a break on line 16 before else

0

Why are you cloning the gun on line 04, Instead you should clone in on 15-16 then change the parent

1

This script is so terrible I don't know how to debug it. Because everything that I'd do would be considered nit-picking but its more organized that way.

2 answers

✓ Accepted answer

Hello, MCrafter49;

Your script is quite... hard to understand, so i have edited the script!

--- It IS supposed to be a Localscript.
 local lvls = game.Players.LocalPlayer.leaderstats.Level.Value --- Notice, if the leaderstats (folder) is inside the localplayer's character, it won't work.
local gun = game.ReplicatedStorage.RedHyperLaser:Clone() --- Clones the ("RedHyperLaser"), MAKE SURE ITS A TOOL!

if lvls == 50 then --- If localplayer's Level is over 50, then.
    gun.Parent = game.Players.LocalPlayer.Backpack --- Gives the gun to the LocalPlayer.
    print("Script is running, no errors until now.") --- Just to make sure.
end

--- Note : I did NOT check it on STUDIO, so errors may exists, thank you for reading until here.

If that script doesn't work, then try this version! Be warned that it may not work.

--- It IS supposed to be a Localscript.
 local lvls = game.Players.LocalPlayer.leaderstats.Level.Value --- Notice, if the leaderstats (folder) is inside the localplayer's character, it won't work.
local gun = game.ReplicatedStorage.RedHyperLaser:Clone() --- Clones the ("RedHyperLaser"), MAKE SURE ITS A TOOL!

function Cloning()
gun.Parent = game.Players.LocalPlayer.Backpack
end

if lvls == 50 then
Cloning()

Hope i helped.

--- AIphanium.

----- Dear MCrafter49, place it in Starterpack, i just noticed that.

local plr = game.Players.LocalPlayer
local lvls = plr.leaderstats.Level.Value
local gun = game.ReplicatedStorage.RedHyperLaser
local gunClone = gun:Clone()
local gunClone.Parent = game.ServerStorage

function clonePart()
    gun:Clone()
    gunClone.Parent = game.ServerStorage

end

clonePart()

function CheckLevel()
	if lvls == 50 then
   		gunClone.Parent = game.Players.LocalPlayer.Backpack 
	else
   		print("Error")
	end
end
lvls.Changed:Connect(function()
	CheckLevel()
end)

CheckLevel()

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