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

How do I make it so when someone clicks a part it gives the player who clicked it a tool?

I want it so when I click the ClickDetector it'll clone a Tool from ServerStorage and put it in the player's backpack, I've come up with this but I don't know what's wrong with it.

local Tool = game.ServerStorage.ToolEx
local Player = game.Players.LocalPlayer
local ClickDet = script.Parent

ClickDet.MouseClick:Connect(function()
	local ClonedTool = Tool:Clone()
	ColendTool.Parent = Player.Backpack
end)

Any help would be much aprichiated!

6 comments

0

Is this in a LocalScript? If not, then it can't pull the LocalPlayer.

0

it isn't should I make it a LocalScript?

0

Yes.

0

That's your problem, LocalPlayer doesn't exist on the server

0

Oh ok, it also gives me an error in the Output, Workspace.ToolEx.Script attempt to index iil with backpack

0

Imma request to lock question.

2 answers

✓ Accepted answer

You are trying to use LocalPlayer in a Server Script what you'll have to use instead is the Player passed in MouseClick(the Player who clicked) like this

local Tool = game.ServerStorage.ToolEx
local ClickDet = script.Parent

ClickDet.MouseClick:Connect(function(Player)
    local ClonedTool = Tool:Clone()
    ClonedTool.Parent = Player.Backpack
end)

You can learn more about ClickDetectors here and about why LocalPlayer doesn't work in this case here

[Answered] Simply not in a LocalScript.

3 comments

0

What do you mean ?

0

It is not in a localscript, it's in an normal one

0

This should be a comment. If it's short enough to fit as a comment, make it a comment.

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