So I am making an item giver so when you click the part, it clones an item from ReplicatedStorage. Here is the code:
local player = game.Players.LocalPlayer function onClicked() game.ReplicatedStorage.PaperSlip:clone().Parent = player.Backpack end script.Parent.ClickDetector.MouseClick:connect(onClicked)
It's in a localscript and it's right inside the part. I have a clickdetector right inside the part too, so I don't know what I did wrong, but it's not doing anything when I click it. Someone please help!
First, LocalScripts do not work on the server. They only work on the client.
Now you're probably gonna ask, "How do I get the player who clicked without a local script?".
The answer is simple. Click Detectors have a player parameter.
What you need to do:
function Clicked(Player) -- Player param to get the player who clicked game.ReplicatedStorage.PaperSlip:clone().Parent = Player.Backpack end script.Parent.ClickDetector.MouseClick:connect(Clicked)
Simple!
I wrote this out in the browser and didn't test it.
local RP = game:GetService("ReplicatedStorage") local Plr = game:GetService("Players").LocalPlayer local BP = Plr:WaitForChild("Backpack") local CD = script.Parent:WaitForChild("ClickDetector") CD.MouseClick:connect(function() if RP:FindFirstChild("PaperSlip") then RP["PaperSlip"]:Clone().Parent = BP end end)
Try this. Also make sure it is called: "PaperSlip". Not something like "Paperslip" or "paperslip".