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

How to move a model depending on where the model position is?

Asked by 3 years ago

Good day,

I created a script that moves a model to a specific position, and the part that receives the model changes folder (to distinguish part with something on it, and others not).

I would like to know how to detect when something is not on the part, to bring back the part to his original folder?

Thank you

local palPart = script.Parent
local db = true
local light = workspace.ReceivingPallet.GreenLight
local Model = workspace.pal12
local cpos = Model.PrimaryPart.Position

palPart.Touched:Connect(function(hit)
    local palToClone = workspace.pal12
    local palStorage = game.Workspace.emptyStorageLocation:GetChildren()
    local numOfStorage = #palStorage

    if db and palToClone then               
        db = false
        local ss = game:GetService("ServerStorage")
        local pal = ss:WaitForChild("pal12")
        local randPalStorage = math.floor(math.random(1, numOfStorage))
        local palClone = pal
        palClone:Clone()
        palClone.Parent = workspace
        Model:SetPrimaryPartCFrame(palStorage[randPalStorage].CFrame + Vector3.new(0,0,0))
        Model.Parent = workspace.storagePallet

    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

I think the MoveTo() function could help you a bit. Example:

local Services = setmetatable({}, {__index=function(self, index)return game:GetService(index) end})

Model:MoveTo(Services.Players.LocalPlayer.Character.HumanoidRootPart.Position)
0
My problem is that the model never touch the player in my game. I’m checking other forum post and maybe I need to give an attributes to the part to say when something touched, and loop to verify? But I’m new at this so I didn’t know how to make that happen…. :( soldnic 0 — 3y
Ad

Answer this question