Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make a part with a ClickDetector give you items randomly?

Asked by 5 years ago
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.

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 User#24403 69 — 5y
0
okay so, ive kind of never scripted in my life Objectionist 5 — 5y
0
Where are the toys inside, what service User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
yo thanks Objectionist 5 — 5y
0
line 5 is confusing me Objectionist 5 — 5y
0
If it helped accept The_Pr0fessor 595 — 5y
Ad

Answer this question