Hello, how would I make a script that clones the chest and spawns it randomly on top of the white part every 10 secs?
thanks!
Hello, how would I make a script that clones the chest and spawns it randomly on top of the white part every 10 secs?
thanks!
The developer forum isn’t for giving out whole scripts.
Because when someone gives you a whole script, you don’t learn anything…
And if it doesn’t work, you probably won’t know how to fix it…
So it looks like your looking for a whole script.
And your not supposes to ask for them here.
The developer forum Scripting Support Section, is only for help with your scripts.
So come back once you’ve tried how to.
You can use the SetPrimaryPartCFrame()
function to set the position and orientation of an entire model using a primary part.
You can generate a random position with something like:
local sizeX = math.floor(platform.Size.X / 2)
local sizeZ = math.floor(platform.Size.Z / 2)
local x = math.random(-sizeX, sizeX)
local z = math.random(-sizeZ, sizeZ)
local position = Vector3.new(x, 0, z)
chest:SetPrimaryPartCFrame(platform.CFrame * CFrame.new(position))
You have the answer right in the question, so your only issue here is trying to turn that answer back into usable code. Think about this more clearly, learn what you need to along the way and set to work.
Rather than giving you a code sample, it would do you better to learn the process of dissecting what you’re trying to do and then turning that back into a work effort. So hopefully you can stay with me here.
“How would I make a script that clones the chest and spawns it randomly on top of the white part every 10 secs?”
Every 10 seconds, clone the chest and move it randomly on top of the white part.
So from that, you can already tell what you might need. When you have the answer in mind, start defining your requirements. Outline what you might need, then put it to practice.
Every 10 seconds, you want something to happen. What do we use to make things run infinitely? A while loop.
You want a chest to be cloned during this time. What do we use to duplicate objects? Clone.
You want the chest to adopt a random position amongst a part. Let’s assume that height (Y axis) is not randomised. We need to then get the outer bounds of the part. You can do this by grabbing the size and dividing it by two. A negative value will flip this around. We then get a random position from these calculations.
You want to place that object at a certain point. What do we use to position models? SetPrimaryPartCFrame. Use the calculated coordinates and place the model down.
There you go. There’s some code above if you want, but I feel like just giving you the code won’t help you here. It’s one thing to have the code but another to understand what exactly you’re doing and how to achieve what you desire.
Good luck.