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

Clone Item form Lighting to player backpack?

function OnClicked()
	game.Lighting["M16A1"]:clone().Parent = player.Backpack
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked) 

Hello I have a problem I try to make a button with dis script that if I push dis button that its copy the item and put it into Player backpack

Can someone make 3 scripts for my

  • Clone backpack
  • Clone item and put in backpack if you have Money
  • a backpack saver script

1 comment

0

Yeah, where are you defining player? That's probably the issue.

3 answers

This is not a request website but

function OnClicked()
if game.Players.LocalPlayer.leaderstats.Money.Value >= 100 then --checks if player has 100 or more money
	game.Lighting.M16A1:Clone().Parent = game.Players.LocalPlayer.Backpack

script.Parent.ClickDetector.MouseClick:connect(OnClicked)

2 comments

0

Dont work and its give error 16:31:31.775 - Players.bolfstar.PlayerGui.Test.Frame.TextButton.Script:5: 'end' expected (to close 'if' at line 2) near ''

0

den put a end statement right there, dum dum. Cmon now. The output box pratically tells you what to put

@GalaxyFPS_Studios This should work

function OnClicked()
	if game.Players.LocalPlayer.leaderstats.Money.Value >= 100 then
		game.ServerStorage.M16A1:Clone().Parent = game.Players.LocalPlayer.Backpack
	end
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)

Also, have the item in ServerStorage, its neater that way

I believe that the abouve script would not work. To detect a clickDetector click, you need a Script, and a Script doesn't have the "LocalPlayer" variable. This Script should work:

local function onMouseClick(player)
	if player.leaderstats.Money.Value >= 100 then
		game.ServerStorage.M16A1:Clone().Parent = player.Backpack
	end
end

script.Parent.ClickDetector.MouseClick:connect(onMouseClick)

I didn't test it, might not work (I will check ASAP)

Pls accept if this helped

I usually don't call funcitons.. Makes me confused. But the problem is that click detectors are only for bricks and parts in the workspace. Since you're using a GUI or frame in a button do this:

script.Parent.MouseButton1Click:connect(function(player)
   game.Lighting.M16A1:Clone().Parent = game.Players.LocalPlayer.Backpack
end)

To make clear I'm going to show you:

script.Parent.MouseButton1Click:connect(function()
--Script here.
end)
--Use this on text buttons and guis.

On parts use this:

script.Parent.ClickDetector.MouseClick:connect(function()
--Script here.
end)
--Put a ClickDetector in the part and the script in that same part,NOT IN THE CLICKDETECTOR.

If that worked accept the answer :D

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