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

How to make it so that when i click a click detector it gives weapon?

I am trying to make it so that when i click a part with a click detector it gives a player a weapon, i dont have a script though so please help, thank you!

2 answers

✓ Accepted answer

This should work

local Tool = game.Lighting.Tool
local part = game.Workspace.Part

part.ClickDetector.MouseClick:connect(function(player)
    local toolClone:Clone()
    toolClone.Parent = player.Backpack
end)

2 comments

1

This might not work in the actual game because you didn't wait for the child to load in.

0

Don't answer with just a script. Explain your solution.

EndorsedScripter was right, but he did miss a few parts and the script won't work if you just randomly place it. He didn't explain as well so I will be helping.

First, a ClickDetector's Event is MouseClick

But before that, we want to make sure we have our variables, follow these steps below;

  1. Make sure this is a script in ServerScriptService or Workspace
  2. Make sure you have a Part that is anchored
  3. Make sure you insert a ClickDetector into the part
  4. Make sure you have the tool inside of ReplicatedStorage

Though I will be making 2 scripts, 1 will work if you did what the instructions above.

The second one was made for skipping steps;

##NOTE## If you decide to skip step 2 AND step 3 then use script #2

Script #1 (If you did everything above):

First, we want to make sure we have the variables, it would look like this;

local Part = game.Workspace:WaitForChild("Part") --Rename 'Part' to what your part is named
local Clicker = Part.ClickDetector --The click detector
local Tool = game.ReplicatedStorage:WaitForChild("ToolName") --Put the exact tool name here

now, we want to fire the function when the ClickDetector is clicked. So it would look like this;

local Part = game.Workspace:WaitForChild("Part") --Rename 'Part' to what your part is named
local Clicker = Part.ClickDetector --The click detector
local Tool = game.ReplicatedStorage:WaitForChild("ToolName") --Put the exact tool name here

Clicker.MouseClicked:Connect(function(plr)

end)

Now we want to clone the tool to the player's BackPack so we would make 2 variables on Click;

local Part = game.Workspace:WaitForChild("Part") --Rename 'Part' to what your part is named
local Clicker = Part.ClickDetector --The click detector
local Tool = game.ReplicatedStorage:WaitForChild("ToolName") --Put the exact tool name here

Clicker.MouseClicked:Connect(function(plr)
	local BackPack = plr.Backpack --The player's Backpack
	local CloneTool = Tool:Clone() --Clones the tool
	CloneTool.Parent = BackPack -- Send's the tool to the player's backpack
end)

This will work if you did what was told above,

Script #2 (If you skipped step1 and step2);

If you have then we will be doing something similar except we will be creating the part and the ClickDetector through the script with Instance.new();

local TG --Tool Giver = Instance.new("Part")
TG.Anchored = true --Make's sure anchored is true
TG.Parent = game.Workspace
TG.Name = "ToolGiver"

local Clicker = Instance.new("ClickDetector")
Clicker.Parent = TG --Send's it to Part
Clicker.Name = "Clicker"

Clicker.MouseClicked:Connect(function(plr)
	local BackPack = plr.Backpack --The player's Backpack
	local CloneTool = Tool:Clone() --Clones the tool
	CloneTool.Parent = BackPack -- Send's the tool to the player's backpack
end)

If this helped you then please accept answer :D

1 comment

0

I spended like 30 minutes writing this ;-;

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