Need help scripting a textbutton to clone a tool

I want to achieve when you click a text button a tool clones into your backpack.

This is the issue, for some reason it is not cloning:

I’ve tried fixing the script, asking friends and such.

This is the script:

local Button = script.Parent
local Cone = game.ReplicatedStorage:WaitForChild("Rainbow Ice Cream Cone")

Button.MouseButton1Click:Connect(function(Plr)
	local backpack = Plr:WaitForChild("Backpack")
	local ClonedIceCream = Cone:Clone()
	ClonedIceCream.Parent = backpack
end)
4 Likes

At “local Button = script.Parent”

try script.Parent.Parent instead

3 Likes

The MouseButton1Click event doesn’t pass the player as an argument to the function, it doesn’t pass any data at all, that’s why Plr is nil.

GuiButton.MouseButton1Click API reference

Instead you can get the player in a local script/client side by doing:

local Plr = game.Players.LocalPlayer

Players.LocalPlayer API Reference

2 Likes

Ok thanks! Would this work if I clicked the delete button to delete the tool from workspace? local Input = game:GetService(“UserInputService”)
local DB = Enum.KeyCode.Delete

if Input.InputEnded == DB then
script.Parent:Destroy()
end

2 Likes

No I don’t believe that would work since UserInputService.InputEnded is an event and has to be connected to a function.

Here’s a similar question which might help you.

UserInputService.InputEnded API Reference

I’d also start a new topic if I was you since this is really not related to the main question.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.