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

How do I provide a random objects to equip?

Asked by 8 years ago

In my game, I am providing bowls of fruit which players can click on to equip a single fruit. I've seen examples of this in other games, such as "Blox Hunt" where players can turn into objects. However for the bowl of fruit, instead of copying the object onto another player, I want to get a single piece of fruit out of the bowl. Is this possible? I am just a beginner, and I don't have any experience in Lua. Thank you!

0
Wait, you want the fruit the be randomized or they can click on whatever fruit they specifically want? StoIid 364 — 8y
0
They can click whatever fruit they specifically want. For example, there is a bowl of apples. After clicking the bowl, they only get one apple. crystalclay 70 — 8y

1 answer

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago

There are a couple different ways you can go about doing this.

The less efficient way, but still a way, would be to place click detectors in each different fruit and place a script inside that does what you're trying to do, when the fruit is clicked.

Info and Example On Click Detectors

Another way would be to make a single LocalScript that detects whenever the player clicks on something. You would then add parameters / if statements to see if the player clicked on a fruit and if they did, it would run a function / do whatever it is you're trying to do with the fruit.

Ex:

local player = game.Players.LocalPlayer --Gets the player that owns the script
local mouse = player:GetMouse() --Gets the player's mouse

mouse.Button1Down:connect(function) --When the player clicks
    print(mouse.Target.Name) --To show what you clicked on ( for testing purposes)
    if mouse.Target.Name == "Fruit" then --Will only run if what you clicked on is named fruit
    --Do stuff
    end
end)

You can choose whatever is easier for you or what is best for what you're trying to do. If you need anymore help or have questions just ask.

Hope this helped!

0
Thank you so much! crystalclay 70 — 8y
Ad

Answer this question