hi i had made crafting craft game but i have some problems that Wheel are not able to turn and move although the properties AngularVelocity of HingeConstraint still change .Pls help me fix that , Thx !
Video:
This is Assemble Code:
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Char)
-- Char.Parent = SS
end)
end)
RS.RemoteEvent.Assemble.OnServerEvent:Connect(function(player,ListOfParts)
local Contraption = Instance.new("Model")
local AnchorPart = Instance.new("Part")
local AnchorPart = Instance.new("Part")
local ControllFolder = Instance.new("Folder")
ControllFolder.Parent = Contraption
ControllFolder.Name = "Motors"
AnchorPart.Size = Vector3.new(1,1,1)
AnchorPart.Position = Vector3.new(0,0,0)
AnchorPart.CanTouch = false
AnchorPart.CanCollide = false
AnchorPart.Anchored = false
AnchorPart.Parent = Contraption
AnchorPart.Transparency = 1
Contraption.PrimaryPart = AnchorPart
Contraption.Parent = workspace
-- Build
for _,PartInfor in pairs(ListOfParts) do
local Part:Model = RS.Buildings:FindFirstChild(PartInfor[1]):Clone()
local WeldConstraint = Instance.new("WeldConstraint")
WeldConstraint.Part0 = Part.PrimaryPart ; WeldConstraint.Part1 = AnchorPart ; WeldConstraint.Parent = AnchorPart
Part:PivotTo(CFrame.new(PartInfor[2].X,PartInfor[2].Y,PartInfor[2].Z))
Part.Parent = Contraption
Part.PrimaryPart.Anchored = false
Part.PrimaryPart.CanCollide = true
end
-- Function
local Seat = nil
for i,v:Model in pairs(Contraption:GetChildren()) do if not v:HasTag("Seat") then continue end Seat = v break end
-- Wheel
for i,v:Model in pairs(Contraption:GetChildren()) do
local function LeftOrRight(Wheel:Model)
local Pos = Wheel.PrimaryPart.Position.X - Seat.PrimaryPart.Position.X
if Pos > 0 then return "L" end
if Pos < 0 then return "R" end
if Pos == 0 then return "_" end
end
if v:HasTag("Wheel") then
v.Name = LeftOrRight(v).."F"
local HingeConstraint = Instance.new("HingeConstraint")
local WheelAttachment = Instance.new("Attachment")
local BodyAttachment = Instance.new("Attachment")
BodyAttachment.Parent = Seat.PrimaryPart
BodyAttachment.WorldCFrame = v.PrimaryPart.CFrame
WheelAttachment.Parent = v.Wheel
WheelAttachment.WorldCFrame = v.PrimaryPart.CFrame
HingeConstraint.Attachment0 = WheelAttachment
HingeConstraint.Attachment1 = BodyAttachment
HingeConstraint.ActuatorType = Enum.ActuatorType.Motor
HingeConstraint.MotorMaxTorque = 200000
HingeConstraint.Parent = ControllFolder
HingeConstraint.Name = LeftOrRight(v).."M"
end
end
-- Add Controller
local ControllScript = RS.Script.Controller:Clone()
ControllScript.Parent = Contraption
end)
Controller Code:
local Contraption = script.Parent
local ControllerFolder = Contraption:FindFirstChild("Motors")
local Seat:VehicleSeat = nil ; local LM:HingeConstraint = {} ; local RM:HingeConstraint = {}
local Speed = 100
local RotateSpeed = 100
for i,v:Model in pairs(Contraption:GetChildren()) do
if v:HasTag("Seat") then
Seat = v:FindFirstChildWhichIsA("VehicleSeat")
end
end
for i,v in pairs(ControllerFolder:GetChildren()) do
if v.Name == "LM" then
table.insert(LM,v)
elseif v.Name == "RM" then
table.insert(RM,v)
end
end
Seat:GetPropertyChangedSignal("Steer"):Connect(function() -- Left/Right
for i,v in pairs(LM) do
v.AngularVelocity = Speed * Seat.Throttle
end
for i,v in pairs(RM) do
v.AngularVelocity = Speed * -Seat.Throttle
end
end)
Seat:GetPropertyChangedSignal("Throttle"):Connect(function() -- Forward/Backward
for i,v in pairs(LM) do
v.AngularVelocity = Speed * Seat.Throttle
end
for i,v in pairs(RM) do
v.AngularVelocity = Speed * Seat.Throttle
end
end)