yo i managed to make a giver but now im trying to make it work on click so do you know why this script doesnt work?
local Giver = script.Parent local Gear = script.Parent.Handgun local idk = false function give(Part) local hum = Part.Parent:findFirstChild("Humanoid") if (hum ~= nil) and idk == false then idk = true local Location = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent) local New = Gear:Clone() New.Parent = Location.Backpack Giver.BrickColor = BrickColor.new("Really red") wait(3) Giver.BrickColor = BrickColor.new("Medium stone grey") idk = false end end Giver.ClickDetector.MouseClick:Connect(give)
You don't put tools in the player. You can either put it in the character or put it in the player's backpack. Here's the fixed script.
local Location = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent).Backpack
Also, FindFirstChild may need to be capitalized, I dunno.
It's because you don't understand what MouseClick
passes as an argument. MouseClick
doesn't pass a part; it passes the player who clicked the ClickDetector
.
Edited script:
local Giver = script.Parent local Gear = script.Parent.Handgun local idk = false function give(Player) if Player then if not idk then idk = true local New = Gear:Clone() New.Parent = Player.Backpack Giver.BrickColor = BrickColor.new("Really red") wait(3) Giver.BrickColor = BrickColor.new("Medium stone grey") idk = false end end end Giver.ClickDetector.MouseClick:Connect(give)
Only Touched
passes a BasePart
as an argument. A ClickDetector's MouseClick
event always passes the player who clicked on the ClickDetector
.