Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

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…. :(

This discussion is preserved as it was. New answers, comments, and votes are closed.