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

I have a GUI and when you click it, it's supposed to give you a sword. Why isn't it working?

So I have this GUI in my game and it's supposed to give you a sword every time you click it. I have the script, but it doesn't work and I don't know what to do about it. Any suggestions? (I'm a beginner)

Here is the code:

sword = game.Lighting.Sword:Clone()
script.Parent.MouseButton1Down:connect(function()
	local Players = game.Players:GetChildren()
	sword.Parent = game.Players.LocalPlayer.Backpack
end)

1 comment

0

is this a localscript or a script, and where is it located

1 answer

Your script works fine in studio but you need to get the specific player so it adds it to the player's specific backpack.


local player = game.Players.LocalPlayer -- Get the LocalPlayer
bp = player:WaitForChild("Backpack") -- Wait for the Backpack.
lighting = game:GetService("Lighting") -- Wait for the Lighting Service

sword = lighting:WaitForChild("Sword") -- // Wait for the sword to load.

script.Parent.MouseButton1Down:connect(function()
    print("Clicked the button!")
	local cloned = sword:Clone() -- Clone the Sword from Lighting.
	cloned.Parent = bp -- Parent it to the Player's backpack.
end)

1 comment

0

one more thing, we don't use Lighting to store stuff anymore. Try using ServerStorage (Server Scripts ONLY) or ReplicatedStorage (for both Server and Local Scripts)!

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