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

Change position of items/tools?

Asked by 5 years ago

Hello! Can someone help me? Im creating a map where someone need to find a card and a key. How do i get change the position of the item in every round?

0
This is not a request site but I can still answer you ( Without a code of course ). You can create 4 ( 4 is an example, you can find more ) local positions and use a math.random script. That's all the information I give, find the rest by googling. SwingingMelons -18 — 5y
0
I'd recommend using math.random() and some invisible parts in your workspace. AswormeDorijan111 531 — 5y
0
Sorry for asking, i dont know so much about scripting and im just watching tutorials of everything. Btw thanks a lot! Chronicalr 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Chronicalr :

let's say you have the card n' key in workspace:

local card = workspace.card
local key = workspace.key

so, we now need to move the MODEL , not the tool object.let's say you put it all in the handle block.

local random1 = Random.new()
local place1 = vector3.new(random1.NextNumber(mapxlength/2,mapxlength/2),200,random1.NextNumber(
-mapxlength/2,mapxlength/2))
local random2 = Random.new()
local place2 = vector3.new(random2.NextNumber(mapylength/2,mapylength/2)200,,random2.NextNumber(
-mapylength/2,mapylength/2))
card.handle.position = place1
key.handle.position = place2

put that all in a function to call it any time.(in this case a round) also, if the card is in weird unintended spots, try intending some spots for the card & key to spawn, use random to pick which spot will it spawn at. this is the full script:

local card = workspace.card
local key = workspace.key
function spawn()
    local random1 = Random.new()
    local place1 =      vector3.new(random1.NextNumber(mapxlength/2,mapxlength/2),200,random1.NextNumber(
-mapxlength/2,mapxlength/2))
    local random2 = Random.new()
    local place2 = vector3.new(random2.NextNumber(mapylength/2,mapylength/2)200,,random2.NextNumber(
-mapylength/2,mapylength/2))
    card.handle.position = place1
    key.handle.position = place2
end
while(1)do
    wait(100) -- the time of one round
    spawn()
end

if you need to use the card or key and deplete it: clone it ,set its parent to workspace every round BEFORE you call the function.

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

how to use random

Random

< Global namespace | Roblox namespace

Random is a datatype used to generate pseudorandom numbers using an dedicated internal state.

Contents
1   Constructors
1.1 Random.new
2   Methods
2.1 NextNumber
2.2 NextInteger
2.3 Clone
Constructors
Random.new
Random.new(double seed)  

Description:
Creates a new Random object from the given seed. If a seed isn’t specified, one will automatically be pulled from an internal entropy source.

Methods
NextNumber
number Random:NextNumber(number min = 0, number max = 1)  

Description:
Returns a pseudorandom number uniformly distributed over [min, max).

NextInteger
int Random:NextInteger(int min, int max)  

Description:
Returns a pseudorandom integer uniformly distributed over [min, max).

Clone
Random Random:Clone()  

Description:
Returns a new Random object with the same state as the original.

~super

Ad

Answer this question