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

why does the children of the car get rotated and placed in a weird way?

i asked this before but i got no answer or comment and not the previous question is on the second page so i though i'd put it here again hoping to get an answer or comment

this is a server script

game.ReplicatedStorage.spawnjeep.OnServerEvent:Connect(function(player)
    if player.leaderstats.Money.Value >= 5000 then
        player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5000
        if game.Workspace:FindFirstChild(player.Name.."Jeep") then
            game.Workspac:FindFirstChild(player.Name.."Jeep"):Destroy()
            game.ServerStorage.Configuration.Jeep:Clone().Parent = game.Workspace
            game.Workspace.Jeep.Name = player.Name.."Jeep"
            for i,v in pairs(game.Workspace:FindFirstChild(player.Name.."Jeep"):GetChildren()) do
                if not v:IsA("Configuration") and not v:IsA("Script") then
                v.Rotation = player.Character.HumanoidRootPart.Orientation
                end
            end
            game.Workspace:FindFirstChild(player.name.."Jeep").Chassis.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position)
        else
            game.ServerStorage.Configuration.Jeep:Clone().Parent = game.Workspace
            game.Workspace.Jeep.Name = player.Name.."Jeep"
            for i,v in pairs(game.Workspace:FindFirstChild(player.Name.."Jeep"):GetChildren()) do
                if not v:IsA("Configuration") and not v:IsA("Script") then
                v.Rotation = player.Character.HumanoidRootPart.Orientation
                end
            end
            game.Workspace:FindFirstChild(player.Name.."Jeep").Chassis.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position)
        end
    end
end)

a picture of how it turns out https://imgur.com/a/XW9Z4W0

1 answer

You can use the SetPrimaryPartCFrame() function to move the entirety of a model. I also tidied up the script a bit.

game.ReplicatedStorage.spawnjeep.OnServerEvent:Connect(function(player)
    if player.leaderstats.Money.Value >= 5000 then
        player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5000
        if game.Workspace:FindFirstChild(player.Name.."Jeep") then
            game.Workspac:FindFirstChild(player.Name.."Jeep"):Destroy()
	end
 game.Workspace:FindFirstChild(player.Name.."Jeep"):SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame)
    end
end)

Just make sure you've set the primary part of the Jeep.

2 comments

0

i already teleport the car to me, what i need is for it to rotate correctly

0

Oh, fixed that for you.

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