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

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

Asked by 5 years ago
Edited 5 years ago

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.

1local Tool = game.ServerStorage.ToolEx
2local Player = game.Players.LocalPlayer
3local ClickDet = script.Parent
4 
5ClickDet.MouseClick:Connect(function()
6    local ClonedTool = Tool:Clone()
7    ColendTool.Parent = Player.Backpack
8end)

Any help would be much aprichiated!

0
Is this in a LocalScript? If not, then it can't pull the LocalPlayer. DetectiveRaie 193 — 5y
0
it isn't should I make it a LocalScript? ANormalPlayer_Alex 11 — 5y
0
Yes. DetectiveRaie 193 — 5y
0
That's your problem, LocalPlayer doesn't exist on the server Filipalla 504 — 5y
View all comments (2 more)
0
Oh ok, it also gives me an error in the Output, Workspace.ToolEx.Script attempt to index iil with backpack ANormalPlayer_Alex 11 — 5y
0
Imma request to lock question. PrismaticFruits 842 — 5y

Locked by PrismaticFruits and DeceptiveCaster

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Filipalla 504 Moderation Voter
5 years ago
Edited 5 years ago

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

1local Tool = game.ServerStorage.ToolEx
2local ClickDet = script.Parent
3 
4ClickDet.MouseClick:Connect(function(Player)
5    local ClonedTool = Tool:Clone()
6    ClonedTool.Parent = Player.Backpack
7end)

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

Ad
Log in to vote
0
Answered by 5 years ago

[Answered] Simply not in a LocalScript.

0
What do you mean ? Nguyenlegiahung 1091 — 5y
0
It is not in a localscript, it's in an normal one ANormalPlayer_Alex 11 — 5y
0
This should be a comment. If it's short enough to fit as a comment, make it a comment. DeceptiveCaster 3761 — 5y