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 4 years ago
Edited 4 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.

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!

0
Is this in a LocalScript? If not, then it can't pull the LocalPlayer. DetectiveRaie 193 — 4y
0
it isn't should I make it a LocalScript? ANormalPlayer_Alex 11 — 4y
0
Yes. DetectiveRaie 193 — 4y
0
That's your problem, LocalPlayer doesn't exist on the server Filipalla 504 — 4y
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 — 4y
0
Imma request to lock question. PrismaticFruits 842 — 4y

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
4 years ago
Edited 4 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

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

Ad
Log in to vote
0
Answered by 4 years ago

[Answered] Simply not in a LocalScript.

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