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

Gui won't let me clone and then equip a tool???

Asked by
4D_X 118
7 years ago
Drink = game.Lighting.Water
script.Parent.MouseButton1Down:connect(function(plr)
nDrink = Drink:Clone()
nDrink.Parent = plr.Backpack
end)

What's wrong with this???

0
Btw it's a surface gui 4D_X 118 — 7y
0
Protip: NEVER store anything important into Lighting (or any tools at all). ServerStorage exists for a reason. block01352 57 — 7y

2 answers

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
7 years ago
Edited 7 years ago

The problem here is MouseButton1Down does not return a player, it returns an X and Y value.

A way to go about what you want is using a LocalScript inside the StarterGui that handles the ScreenGui instead, and using the LocalPlayer to get the player value.

Hope this helps!

If you need some help with the method above, comment and I'll write you up something

Ad
Log in to vote
0
Answered by 7 years ago
-- Inside a Localscript placed within StarterPlayerScripts
local plr = game.Players.LocalPlayer
local gui = game.Workspace.ToolTest.SurfaceGui
local button = gui.Frame.TextButton

-- Replaced Water for testing purposes
-- Also NEVER put tools into Lighting. ReplicatedStorage or ServerStorage is more recommended.
Drink = game.ReplicatedStorage.GravityCoil

button.MouseButton1Click:Connect(function()
        local nDrink = Drink:Clone()
        nDrink.Parent = plr.Backpack
end)

Hope this helps!

Answer this question