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

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

Asked by 8 years ago

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)
0
is this a localscript or a script, and where is it located thehybrid576 294 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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)
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)! starlebVerse 685 — 8y
Ad

Answer this question