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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
i already teleport the car to me, what i need is for it to rotate correctly Gameplayer365247v2 1055 — 4y
0
Oh, fixed that for you. Vinceberget 1420 — 4y
Ad

Answer this question