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

Clone Item form Lighting to player backpack? [closed]

Asked by 6 years ago
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

0
Yeah, where are you defining player? That's probably the issue. gitrog 326 — 6y

Closed as Not Constructive by RubenKan

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

3 answers

Log in to vote
0
Answered by
Galicate 106
6 years ago
Edited 6 years ago

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)
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 '<eof>' bolfstar 2 — 6y
0
den put a end statement right there, dum dum. Cmon now. The output box pratically tells you what to put User#19492 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

@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

Log in to vote
0
Answered by 6 years ago

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