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

How to transport a part to the exact position of another part?

Asked by 7 years ago

I'm new to coding in roblox studio, and as a beginner project I decided to make an apple tree with apples growing and falling off of the tree. I put parts all around the tree to work as 'Apple Spawns'. I made a script that in 3 second intervals, randomly chooses an Apple Spawn, and adds a value of 1 to it. Once the apple spawn reaches 5, I want an apple to appear right at the spot of the apple spawn. Only problem is I don't know how to do so. I thought maybe if i can find a way to get the Vector3.p of the apple spawn, and paste it into an apple, I could get the results I wanted. Except I don't know how. Maybe I am just overthinking it and there is some perfect command or function that does this normally. I'm not asking for you to do the script for me, I just want to be pointed in the right direction. The script is below, feel free to tell me if its horrible or not. Just remember I am a beginner.

FruitSpawnScript

`FruitSpawn = script.Spawn:GetChildren(">5")[math.random(1)]
FruitSpawnPosition = FruitSpawn Vector3 --???
FruitLocation = FruitSpawn Vector3 CFrame.p()--???
Apple = script.Apple:Clone()


function AppleSpawn()
    if FruitSpawn[math.random(1)] >= 5 then
        Apple:MoveTo(FruitLocation)--???
        wait(3)
        Apple.Anchored = false
    else
        wait(1)
    end

end

AppleSpawn()`

FruitGrowthScript

`FruitSpawn = script.Parent:GetChildren("Part")[math.random(1)]
function FruitGrowth()
    FruitSpawn = FruitSpawn + 1
    wait(1)

    if FruitSpawn > 10 then
        FruitSpawn = FruitSpawn - 5
        wait(1)
    end
end
`
0
:MoveTo(vector3) -- see roblox wiki for more info AdministratorReece 193 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

You can delete lines 2 and 3, and unless script.Apple is a model, :MoveTo() won't work, seeing as it's made to move models. If it's a part, just change line 9 to:

 Apple.Position = FruitSpawn.Position

Because you can change the position of parts just by setting it. If it IS a model, change line 9 to:

Apple:SetPrimaryPartCFrame(FruitSpawn.CFrame) 

As this is a function meant for models. Also, keep in mind that Position is a vector3 value that references location, while CFrame is both location and rotation, and that you must set the primary part of the model in the model's properties tab (If you go to the view tab in Roblox Studio, you can see the Properties button next to explorer.)

Ad
Log in to vote
0
Answered by
Bertox 159
7 years ago

If it's just a part then

PartOne.CFrame = PartTwo.CFrame

That's it. I hope I didn't understand your question wrong.

Answer this question