I decided I will give a shot at making a lifting simulator for fun. One thing I couldn’t wrap my head around though is making it so when you lift the weight, the gui arm would appear somewhere random on the screen, or preferably have it choose one of let’s say 5 set positions.
The issue is I don’t know the best way to approach this, and I don’t know how I would even achieve this.
I’ve tried using math.random and generating a random number, but that didn’t work of course.
Here is the portion of the script I have so far: (Local script by the way.)
local tool = script.Parent
local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui.Main.LiftingImage
tool.Activated:Connect(function()
gui.Position = --This is the area I do not understand.
end)
Let’s not compare speed here, because the speed difference is negligible. There are only slight differences in the code sample: one calls a global and the other creates an object of the Random class, assigned to a local upvalue.
The Random object and math.random use the same algorithm but depending on your use case, you may want to change up which one you’re using. As Random is an object, that also means it sports a plethora of API that you may want to use.
Here’s a scenario: instead of calling math.randomseed (which globally affects seeding and can cause conflictions if multiple scripts are relying on it), you can pass a seed to Random for deterministic results or leave it blank. No argument in Random.new (no fixed seed) pulls a seed from an internal source of entropy and will effectively be local towards that object.