#how do you move a model with a script

1 messages · Page 1 of 1 (latest)

solemn prawn
#

before you to tell me to research, i have
ive even asked AI to make a script
nothing works
ive tried MoveTo() and PivotTo(), pivot to changes the models coordinates in code but does nothing and moveto does nothing flat-out

-- Settings
local Spread = 12
local Range = 4

-- Initial Setup
ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"
ColorBleed.Parent = workspace

-- Simlight Setup
local Simlight = Instance.new("Part")
Simlight.Name = "Simlight"
Simlight.Transparency = 1
Simlight.Size = Vector3.one
Simlight.CanCollide = false
Simlight.CanTouch = false
Simlight.CanQuery = false
Simlight.Anchored = true
local PointLight = Instance.new("PointLight")
PointLight.Range = 6
PointLight.Parent = Simlight

-- Light Placement
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
    local Char = game.Players.LocalPlayer.Character
    local PlayerLocus = 8*Vector3.new(
        math.round(Char.HumanoidRootPart.Position.X/8),
        math.round(Char.HumanoidRootPart.Position.Y/8),
        math.round(Char.HumanoidRootPart.Position.Z/8)
    )
    for i = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
        for j = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
            for k = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
                local clone = Simlight:Clone()
                clone.Position = PlayerLocus + Vector3.new(i,j,k)
                clone.Parent = ColorBleed
            end
        end
    end
end)
ColorBleed.PrimaryPart = ColorBleed:FindFirstChild("Simlight")

ColorBleed:MoveTo(Vector3.new(0,100,0))

-- Light Running
while true do
    task.wait()
end

here's all of my code, once you get to me trying to set a primary part you get to where i just dont know whats happening anymore, everything else works and all the code seems to run

#

this is a localscript but if any of these features didnt work on a localscript id assume the script would tell me that

ashen tusk
# solemn prawn this is a localscript but if any of these features didnt work on a localscript i...

local TweenService = game:GetService("TweenService")

-- Replace "YourModelName"
local model = workspace:WaitForChild("YourModelName")

if not model.PrimaryPart then
warn("PrimaryPart is not set for the model!")
return
end

-- New position to move the model to
local newPosition = Vector3.new(100, 10, 50)

local targetCFrame = CFrame.new(newPosition)

local tweenInfo = TweenInfo.new(
3, -- Time in seconds
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)

local tween = TweenService:Create(model.PrimaryPart, tweenInfo, {
CFrame = targetCFrame
})

-- Move the entire model based on the PrimaryPart's CFrame
tween:Play()

movement
tween.Completed:Connect(function()
print("Model has moved.")
end)

Added some notes to help you understand it, I think it works.

ashen tusk
solemn prawn
#

by the way im just trying to move the thing im not doing anything related to tweening

#

just trying to teleport it

ashen tusk
#

if not model.PrimaryPart then
warn("PrimaryPart not set! Trying to set it now...")
local mainPart = model:FindFirstChild("MainPart")
if mainPart then
model.PrimaryPart = mainPart
print("PrimaryPart successfully set.")
else
error("MainPart not found in model!")
end
end

-- this will move it
model:SetPrimaryPartCFrame(CFrame.new(100, 10, 50))

ashen tusk
solemn prawn
#

?

ashen tusk
# solemn prawn ?

Select the Model in the Explorer. In the Properties panel, find PrimaryPart.

solemn prawn
#

what im mostly confused about is why this isnt working ColorBleed.PrimaryPart = ColorBleed:FindFirstChild("Simlight")

#

its not like it doesnt have enough options

ashen tusk
#

WAIT

ashen tusk
ashen tusk
solemn prawn
#

theres nothing preset in the world the script is all of it

ashen tusk
solemn prawn
ashen tusk
#

oh

ashen tusk
# solemn prawn by the script

local ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"

local simlight = Instance.new("Part")
simlight.Name = "Simlight"
simlight.Size = Vector3.new(4, 1, 2)
simlight.Position = Vector3.new(0, 5, 0)
simlight.Anchored = true
simlight.Parent = ColorBleed -- MUST parent before setting PrimaryPart

ColorBleed.Parent = workspace

exists
ColorBleed.PrimaryPart = simlight

ColorBleed:SetPrimaryPartCFrame(CFrame.new(100, 10, 50))

solemn prawn
#

i never parent simlight to colorbleed i only parent clones

#

i dont parent the original

ashen tusk
exotic veldtBOT
#

studio** You are now Level 2! **studio

ashen tusk
#

local simlightTemplate = game.ReplicatedStorage:WaitForChild("Simlight")

local ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"

local simlightClone = simlightTemplate:Clone()
simlightClone.Parent = ColorBleed

ColorBleed.Parent = workspace

ColorBleed.PrimaryPart = simlightClone

ColorBleed:SetPrimaryPartCFrame(CFrame.new(100, 10, 50))

#

@solemn prawn

solemn prawn
ashen tusk
solemn prawn
ashen tusk
# solemn prawn

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local simlightTemplate = ReplicatedStorage:WaitForChild("Simlight")

local ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"

PrimaryPart)
local mainSimlight = simlightTemplate:Clone()
mainSimlight.Parent = ColorBleed

ColorBleed.PrimaryPart = mainSimlight

for i = 1, 5 do
local extra = simlightTemplate:Clone()
extra.Parent = ColorBleed
end

ColorBleed.Parent = workspace

-- Teleport the model
local newPosition = Vector3.new(100, 10, 50)
ColorBleed:SetPrimaryPartCFrame(CFrame.new(newPosition))

solemn prawn
#

read
my script

ashen tusk
ashen tusk
#

give me a minute

#

-- Initial Setup
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"
ColorBleed.Parent = workspace

local simlightTemplate = ReplicatedStorage:WaitForChild("Simlight")
local primaryClone = simlightTemplate:Clone()
primaryClone.Name = "Simlight" -- optional
primaryClone.Position = Vector3.new(0, 5, 0)
primaryClone.Anchored = true
primaryClone.Parent = ColorBleed

ColorBleed.PrimaryPart = primaryClone

for i = 1, 5 do
local clone = simlightTemplate:Clone()
clone.Name = "Simlight"
clone.Position = Vector3.new(i * 6, 5, 0)
clone.Anchored = true
clone.Parent = ColorBleed
end

local destination = Vector3.new(100, 10, 50)
ColorBleed:SetPrimaryPartCFrame(CFrame.new(destination))

#

@solemn prawn

solemn prawn
#

this is a standalone script with nothing stored anywhere else whether that be in replicatedstorage or elsewhere
as i try to create a large grid of lights, and need to move the model as a whole, i assumably need to choose any of these lights as a primarypart to move the model (for some reason), however the issue is my code that should pick a light as a primarypart instead does absolutely nothing as if there were no lights in the first place

its wonderful that you want to help me and i thank you for that but rather than finding an error in my code you are instead creating your own code that only very vaguely mimics mine

ashen tusk
#

-- Create the model
local ColorBleed = Instance.new("Model")
ColorBleed.Name = "ColorBleed"
ColorBleed.Parent = workspace

-- Create a 5x5 grid of lights
local gridSize = 5
local spacing = 6
local primaryAssigned = false

for x = 0, gridSize - 1 do
for z = 0, gridSize - 1 do
local light = Instance.new("Part")
light.Name = "Simlight"
light.Size = Vector3.new(4, 1, 4)
light.Anchored = true
light.Position = Vector3.new(x * spacing, 5, z * spacing)
light.Parent = ColorBleed
PrimaryPart
if not primaryAssigned then
ColorBleed.PrimaryPart = light
primaryAssigned = true
end
end
end

if ColorBleed.PrimaryPart then
ColorBleed:SetPrimaryPartCFrame(CFrame.new(100, 10, 100))
else
warn("PrimaryPart was never set!")
end

#

hope this works

solemn prawn
#

so for the first go-around in the loop it assigns the primary part and then the rest are clear to go
this actually helped ill try this in a bit thanks

solemn prawn
# ashen tusk Did it work

the primary part thing worked, i just did this

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
    local Char = game.Players.LocalPlayer.Character
    local PlayerLocus = 8*Vector3.new(
        math.round(Char.HumanoidRootPart.Position.X/8),
        math.round(Char.HumanoidRootPart.Position.Y/8),
        math.round(Char.HumanoidRootPart.Position.Z/8)
    )
    local clone
    for i = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
        for j = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
            for k = -(Spread*Range)-(Spread/2), (Spread*Range)+(Spread/2), Spread do
                clone = Simlight:Clone()
                clone.Position = PlayerLocus + Vector3.new(i,j,k)
                clone.Parent = ColorBleed
            end
        end
    end
    ColorBleed.PrimaryPart = clone
end)
#

naturally, still cant move

#

i havent tried the deprecated primary part move thingy which is probably what ill have to use

exotic veldtBOT
#

studio** You are now Level 14! **studio