Hello everyone,
I am making a custom character and I have seemed to run into a problem. The education.roblox mentions to use weld constraints to weld the parts to the humanoid, but when I did that and tried to play none of the controls seems to work. Previously I wrote my code using a single part and worked perfectly. The script I made for the character makes the character like a spaceship and it made it fly. Now with the new character, the spaceship does not fly. I tried adjusting the body velocity and adding more speed, but no luck.
Ask if I need to add more info or need to clarify.
Thanks for the Help!
yeah, but my player script, I wrote it, is not working like intended when there are more than one part; u can try it with one part vs multiple parts.
Code:
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
Controls:Disable()
local RunService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
player.CharacterAdded:Connect(function(char)
hrp = char:WaitForChild("HumanoidRootPart")
end)
local mouse = player:GetMouse()
local mouse_x = mouse.Hit.X
local mouse_y = mouse.Hit.Y
local mouse_z = mouse.Hit.Z
local b_gyro = hrp:WaitForChild("BodyGyro")
local b_velocity = hrp:WaitForChild("BodyVelocity")
local lv
local forward_key = Enum.KeyCode.W
local holding
local speed = 1250
b_velocity.Velocity = Vector3.new(0,0,0)
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == forward_key then
holding = true
end
while holding == true do
b_gyro.CFrame = CFrame.new(hrp.Position,mouse.Hit.p)
lv = b_gyro.CFrame.LookVector
b_velocity.Velocity = Vector3.new(lv.X * speed, lv.Y * speed, lv.Z * speed)
wait()
end
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == forward_key then
holding = false
repeat
b_velocity.Velocity = b_velocity.Velocity * 0.983
wait()
until b_velocity.Velocity == Vector3.new(0,0,0)
end
end)
function GetDeltaTime()
local current = tick()
return tick() - current
end
while true do
b_gyro.CFrame = CFrame.new(hrp.Position,mouse.Hit.p)
lv = b_gyro.CFrame.LookVector
RunService.Heartbeat:Wait()
end
Um, @testingacc333330, the code works when the character only has a single part, but when more parts are introduced (such as a spaceship) the code doesn’t work
@testingacc333330, this issue is related to custom character, :GetChildre() will not do anything, since the humanoid root part (hrp) is the one that controls the characters. For example, hrp in the default character, controls the rotation and the position of rest of the body. To elaborate, when the hrp moves forward, the arm moves automatically and so does the other body parts. Custom character has different properties, here is a link: https://education.roblox.com/en-us/resources/education/arcade/customCharacter.