My posts never actually get any responses for some reason. I hope this one gets through. I want to create a script that keeps the player from sliding and jittering on a fast moving train.
The player will constantly slide around while the train is moving at high speeds.
Ive scowered the devforum for answers, but all either dont give a proper response or use a different method to move the train, though i want it to be physics based. I tried making my own but it doesn’t change anything. The script is on a seperate post.
If anyone could give a proper solution to this, it would be greatly appreciated. Ive seen many games accomplish this but I have no idea how.
this was the script i had before. It was trying to update the player’s assemblylinearvelocity every frame to move it with any part it touches.
local RunService = game:GetService("RunService")
lp = game:GetService("Players").LocalPlayer
char = lp.Character
while lp.Character == nil do wait() char = lp.Character end
char = lp.Character
RunService.RenderStepped:Connect(function()
for _,p in pairs(char:GetDescendants()) do
if p:IsA("BasePart") or p:IsA("MeshPart") then
if char:FindFirstChild("HumanoidRootPart") then
local h
local function onHit(hit)
if p.Name ~= "HumanoidRootPart" then
--p.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
end
if not char:FindFirstChild(hit.Name, true) then
char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(hit.AssemblyLinearVelocity.X, char.HumanoidRootPart.AssemblyLinearVelocity.Y ,hit.AssemblyLinearVelocity.Z)
end
h:Disconnect()
end
h = p.Touched:Connect(onHit)
end
end
end
end)
I FOUND THE SOLUTION. the moving script has to be Serversided and inside of the hitbox of the train! for anyone else struggling with this, here is the code.
part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
local hu = hit.Parent:FindFirstChildWhichIsA("Humanoid")
local huroot = hit.Parent:FindFirstChild("HumanoidRootPart")
huroot.AssemblyLinearVelocity = Vector3.new(part.AssemblyLinearVelocity.X, huroot.AssemblyLinearVelocity.Y ,part.AssemblyLinearVelocity.Z)
end
end)