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 part with a ClickDetector give you items randomly?

local clickDetector = script.Parent.ClickDetector

function onMouseClick()
	
end

clickDetector.MouseClick:connect(onMouseClick)

This is what i have so far. i know its just a clickdetector script that does nothing, but its groundwork. how could i edit this so that it gives you random items, (in this case, toys) everytime you click it? Thanks, hope i get answers soon.

3 comments

0

Where are the toys, in like replicated storage or server storage? You can clone one of the toys out from there into the player's backpack, and ps connect is deprecated in favour of Connect, and don't use global variables, onMouseClick is global, to make it local just do local function, just before function put local

0

okay so, ive kind of never scripted in my life

0

Where are the toys inside, what service

1 answer

local clickDetector = script.Parent.ClickDetector
local GroupOfToys = --[[Set Variable, Like to a Folder of toys or a model or something with a group of toys ]]:GetChildren()
function onMouseClick()
	local Given = GroupOfToys[math.random(1, #GroupOfToys)]:Clone()
	Given.Parent = --[[The Character]]
end

clickDetector.MouseClick:connect(onMouseClick)

3 comments

0

yo thanks

0

line 5 is confusing me

0

If it helped accept

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