Goal:
My end goal is not to get this to work (I have workarounds), but to know why this happens and if this should even be possible
Issue:
My Part position does not correctly get set in the target game. However, it does get set in studio, and in an isolated baseplate world. The code has been tested exactly as written.
Question:
My question is, should this even be possible? This script, to the best of my knowledge, directly sets the position and then prints the results without yielding.
I do not believe it should even be possible for some other script to effect the result here, at least not until after we print it. However, the printed target position and the resulting position of the part do not match. As such, I believe any external code is causing the issue, but how?
ServerScript:
Full example
local myPart = Instance.new("Part")
myPart.Anchored =true
--myPart.Transparency = 1
myPart.CanCollide = false
myPart.Name="ShootingStarSpawner"
myPart.Parent = game.Workspace
while wait(1) do
print("Will Move Star")
local newPos = Vector3.new(10,10,10)
-- Prints correct position
print("Set: X: " .. newPos.X .. " Y: " .. newPos.Y .. " Z:" .. newPos.Z)
-- None of these work in target game. Both work in studio, and in a published baseplate world
--myPart.Position = newPos
myPart.CFrame = CFrame.new(newPos)
-- Prints in game : "Result: X: 0 Y: 0 Z: 0"
-- Prints in studio/baseplate: "Result: X: 10 Y: 10 Z: 10"
print("Result: X: " .. myPart.Position.X .. " Y: " .. myPart.Position.Y .. " Z:" .. myPart.Position.Z)
print("Star Moved")
end
The important question in the code is, why this is possible, and why does it occur in this non-yeilding code segment.
myPart.CFrame = CFrame.new(newPos)
-- Prints in game : "Result: X: 0 Y: 0 Z: 0"
-- Prints in studio/baseplate: "Result: X: 10 Y: 10 Z: 10"
print("Result: X: " .. myPart.Position.X .. " Y: " .. myPart.Position.Y .. " Z:" .. myPart.Position.Z)
Further testing reveals that adding a wait(1) prior to parenting the part to the workspace bypasses the issue. Additionally, the problem only exists if we fail to set Part.Achievable to false before some external script does. This is NOT an issue if we set it to false ourselves in the script. I was unable to reproduce the issue in a baseplate world with another script setting Achievable to false between moves.
What might I be missing that could cause this?
Things I have confirmed:
Part is still parented to workspace
SOLVED! Cause:
External script hooked into a Change event, and changed the values behind the scenes, and in the same thread as the script printing. All extra odd behaviour like in-game only problems, and non-achievable only issues are due to conditions in its code.