#Models facing different directions

1 messages · Page 1 of 1 (latest)

robust fern
#

I've been working on a code for someone's game to have engines spawn upon interacting with a UI, and the code is working, except that the engines have a set orientation they are seemingly randomly facing every time I try to spawn them in. They are all facing the same way in ServerStorage, so I don't understand why they change orientation once they spawn. I think there's an easy fix to it, I just don't have that knowledge since I'm fairly new to Roblox coding 🥲

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnEngineEvent = ReplicatedStorage:WaitForChild("SpawnEngine")
local Spawners = game.Workspace.Spawners

SpawnEngineEvent.OnServerEvent:connect(function(player, engineName)
    local Engine = ServerStorage:FindFirstChild("Engines"):FindFirstChild(engineName)
    if Engine then
        for _, item in pairs(Spawners:GetDescendants()) do
            if item:GetAttribute("Location") == 1 then
                local clonedEngine = Engine:Clone()
                clonedEngine.Name = player.Name .. 'sEngine'
                clonedEngine.Parent = game.Workspace["Player's Engines"]
                clonedEngine:PivotTo(CFrame.new(item.CFrame.Position))
                --[need code here to fix the orientation of the engine]
                item:SetAttribute("Location", 0)
            end
        end
    end
end)
robust fern
#

I've got an update to the code cuz I've still been working on this:

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnEngineEvent = ReplicatedStorage:WaitForChild("SpawnEngine")
--local DeleteEngineEvent = ReplicatedStorage:WaitForChild("DeleteEngine") [optional]
local Spawners = game.Workspace.Spawners

SpawnEngineEvent.OnServerEvent:connect(function(player, engineName)
    local Engine = ServerStorage:FindFirstChild("Engines"):FindFirstChild(engineName)
    if Engine then
        for _, item in pairs(Spawners:GetDescendants()) do
            if item:GetAttribute("Location") == 1 then
                local clonedEngine = Engine:Clone()
                clonedEngine.Name = player.Name .. 'sEngine'
                clonedEngine.Parent = game.Workspace["Player's Engines"]
                clonedEngine:PivotTo(item.CFrame)
                item:SetAttribute("Location", 0)
            end
        end
    end
end)

This sets the orientation of the cloned engines to (0, 180, 0) without actually rotating it. For some odd reason, when my partner sent me the engines, their orientations weren't listed as the same despite all facing the same direction. I want to add a line of code that will rotate it depending on the Engine's orientation in the ServerStorage, but it's difficult given that there is no CFrame for Models.

#

If there is something I can add that'll help me with this issue I haven't been able to find it and I'd really appreciate any assistance 🥹

torpid prawn
#

then just add a cframe for the models

#

and just because you changed/ rotated their direction in serverstorage dosen t mean it would be the same in playtest

#

serverstorage only uses storage, not memory

#

you should put them in replicatedstorage

#

so just change ServerStorage with ReplicatedStorage

robust fern
#

I was overcomplicating this shit so much, I literally just changed the WorldPivot and I got it working 😭 I feel so stupid I was stuck on that for two days LOL