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

how do i make a giver that works with click detector?

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)

2 answers

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.

4 comments

0

doesnt work

0

also lmao u just copied those 2 lines from the script

0

I forgot to edit them

0

fixed.

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.

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