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

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

Asked by 7 years ago

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!

Closed as Not Constructive by OldPalHappy

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?

2 answers

Log in to vote
-1
Answered by 7 years ago

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)
1
This might not work in the actual game because you didn't wait for the child to load in. BlackOrange3343 2676 — 7y
0
Don't answer with just a script. Explain your solution. OldPalHappy 1477 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

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

0
I spended like 30 minutes writing this ;-; BlackOrange3343 2676 — 7y