Hi, I am trying to make this so when the player touches another players head, and the raycast detects it, it makes the player slip backwards:
My code:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local Player = Players.LocalPlayer
RunService.RenderStepped:Connect(function()
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character and Character:FindFirstChild("HumanoidRootPart") then
local original = Character.HumanoidRootPart.AssemblyLinearVelocity
local RaycastResult = Workspace:Raycast(Character.HumanoidRootPart.CFrame.Position, Vector3.new(0, -3, 0))
if RaycastResult and RaycastResult.Instance then
local Hit = RaycastResult.Instance
if Hit.Name == "Head" or Hit.Name == "Torso" or Hit.Name == "HumanoidRootPart" or Hit.Name == "Handle" then
end
end
end
end)
RunService.RenderStepped:Connect(function()
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character and Character:FindFirstChild("HumanoidRootPart") then
local original = Character.HumanoidRootPart.AssemblyLinearVelocity
local RaycastResult = Workspace:Raycast(Character.HumanoidRootPart.CFrame.Position, Vector3.new(0, -3, 0))
if RaycastResult and RaycastResult.Instance then
local Hit = RaycastResult.Instance
if Hit.Name == "Head" or Hit.Name == "Torso" or Hit.Name == "HumanoidRootPart" or Hit.Name == "Handle" then
Character.Humanoid.PlatformStand = true
task.wait()
for i = 1, 10 do
Character.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(i*2), 0, 0)
task.wait()
end
task.wait(0.6)
Character.Humanoid.PlatformStand = false
end
end
end
end)
Thank you, but i dont want them to platform stand, i want them to slip backwards, kind of like a conveyor belt or ice
This is the code I have come up with but the raycast seems delayed and doesnt detect the player touching another players head unless you jump on it:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local Player = Players.LocalPlayer
RunService.Heartbeat:Connect(function()
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character and Character:FindFirstChild("HumanoidRootPart") then
local original = Character.HumanoidRootPart.AssemblyLinearVelocity
local RaycastResult = Workspace:Raycast(Character.HumanoidRootPart.CFrame.Position, Vector3.new(0, -3, 0))
if RaycastResult and RaycastResult.Instance then
local Hit = RaycastResult.Instance
if Hit.Name == "Head" or Hit.Name == "Torso" or Hit.Name == "HumanoidRootPart" or Hit.Name == "Handle" then
Character.HumanoidRootPart.Velocity = Hit.CFrame.lookVector *-40
end
end
end
end)