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!
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)
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;
- Make sure this is a script in ServerScriptService or Workspace
- Make sure you have a Part that is anchored
- Make sure you insert a ClickDetector into the part
- 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;
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
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?