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

Setting CFrame of Primary Part doesn't work?

Asked by 3 years ago

I have recently started testing my game again but I've come to realize what I've been using doesn't work anymore. Has something been updated that I haven't been aware of? Below is what part of the script is used to spawn the model into the map. Did I do something wrong that has come to fruition now with updates? (The ship models are completely unanchored, welded together and placed in ReplicatedStorage)

function locate(player)
    local spawns = workspace.map.spawns --finds the spawn parts located on the current map
    local team = teamsservice.find(player) --finds the team that the player is currently assigned
    local tospawn = spawns:FindFirstChild(team) --finds the folder in the spawns that holds that team's spawns
    local spawners = tospawn:GetChildren() --gets the part pool
    local randomspawn = spawners[math.random(#spawners)] --finds  a random spawner
    return(randomspawn.CFrame) --returns the CFrame
end

local shiptospawn = shiptospawn:Clone()
shiptospawn.body.PrimaryPart.Anchored = true        
shiptospawn.Parent = workspace.ships

local location = locate(player) --gets CFrame of a spawn from above
shiptospawn.body.PrimaryPart.CFrame = location --should set the ship model down on the spawn

--below parents the BodyVelocity and Gyro to the model.
local velocity = script.BodyVelocity:Clone()
velocity.Parent = shiptospawn.body.PrimaryPart

local gyro = script.BodyGyro:Clone()
gyro.Parent = shiptospawn.body.PrimaryPart

local ygyro = script.BodyGyro:Clone()
ygyro.Name = 'YBodyGyro'
ygyro.MaxTorque = Vector3.new(0,math.huge,0)
ygyro.Parent = shiptospawn.body.PrimaryPart

shiptospawn.body.PrimaryPart.Anchored = false

2 answers

Log in to vote
0
Answered by 3 years ago

Instead of doing:

shiptospawn.body.PrimaryPart.CFrame = location

You should do:

shiptospawn.body:SetPrimaryPartCFrame(location)

I'm not sure if that's the problem, but it could possible be.

Ad
Log in to vote
0
Answered by 3 years ago

I resolved this issue by anchoring the ship AFTER I teleported it. Apparently, you cant change the CFrame of anchored parts anymore?

instead of this:

shiptospawn.body.PrimaryPart.Anchored = true
shiptospawn.body.PrimaryPart.CFrame = location

this now works:

shiptospawn.body.PrimaryPart.CFrame = location
shiptospawn.body.PrimaryPart.Anchored = true

Answer this question