Like if you made a Cupcake. How does people grab it when they click it? Is there a Script? Please help me.
I'll Explain it whilst building it up, create a Tool and then Create a part for your cake then inset the part into tool
using basic objects insert a clickdetector into the cake.
ok now insert a script into the cake and lets begin coding
ok first you you need to declare a local so local cake =
And put where the Cake's Tool is located e.g if it's in the workspace and the part's name is cake then it would be local cake = game.Workspace.Tool.cake
get it?
ok now then we need to connect a function when the cake is clicked, so we'll use a anonymous function, Which is the same as a normal function but it's faster to type. so
cake.MouseDetector.MouseButton1Click:connect(function(clicker)
end)
but we'll also need to define a player so use the best method:
local Player = game:GetService'Players'.LocalPlayer
But it might take soem time to load the player so lets add repeat wait() until Player
so the script starts when player is there
Ok then now we write our code, so since I've doen you the basics lets look at the script:
local cake = game.Workspace.Tool.cake local Player = game:GetService'Players'.LocalPlayer repeat wait() until Player cake.ClickDetector.MouseButton1Click:connect(function() if Player then -- double check to make sure Player exists local cakeclone = cake:Clone() -- Clone the cake cakeclone.Parent = Player.Backpack -- where the clone goes end -- end our if statement end) end our function
if you're used to function onClick()
then you may be wondering if the function we used is somehow different? It's not exactly, Because the only difference is we already connect the function to our trigger whilst defining our function. and That's all. If it worked be sure to mark as answered if not post a comment below and I'll fix it.
Closed as Not Constructive by EzraNehemiah_TF2, HungryJaffer, and YellowoTide
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?