Hi, I have a script which very poorly detects when a player touches another player’s head, and I was wondering if there was any way to make it so it only affects the player that touches your head.
Script (part is parented to the players head, and welded):
local Part = script.Parent.Parent
while task.wait(.1) do
Part.Velocity = Part.CFrame.LookVector *-12
end
This current script also affects the players velocity, causing them to move weirdly. Any help would be appreciated, thanks!
local Head = -- path to players head.
Head.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum and not hit:IsDescendentOf(Head.Parent) then
hum.RootPart.Velocity = hum.RootPart.CFrame.LookVector*12
end
end)
I am now using ZonePlus, but it is still very dodgy:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Storage"):WaitForChild("Modules")
local ZonePlus = require(Modules:WaitForChild("Zone"))
local Part = script.Parent.Parent
local Zone = ZonePlus.new(Part)
Zone.itemEntered:Connect(function(Item)
if Item.Name == "Left Leg" then
print("Left Leg en")
Part.Velocity = Part.CFrame.LookVector *-12
elseif Item.Name == "Right Leg" then
print("Right Leg en")
Part.Velocity = Part.CFrame.LookVector *-12
end
end)
Zone.itemExited:Connect(function(Item)
if Item.Name == "Left Leg" then
--Part.Velocity = Vector3.new(0,0,0)
elseif Item.Name == "Right Leg" then
--Part.Velocity = Vector3.new(0,0,0)
end
end)
I apologies, your script works, I had another script in my character causing that issue, but I am wondering if there is any way to make the velocity go faster, so you slip off the players head, and there is no way to go forward without slipping.
Instead of using touched property maybe check the humanoid FloorMaterial instance and check if it name Head and under a model that has Humanoid? I’m on phone right now so I think that I can only give idea
tried that, still doesnt give any results, can you give an example of how i can set the velocity so it works, u dont have to write me the rest of the script
You might want to use LinearVelocity instead though, as I recently heard that BodyVelocity is now deprecated. I haven’t coded in Roblox studio in a while, so I’m kind of behind lol
detects when its being touched now, but doesnt make the player who touches the other player’s head slip, instead pushes both of them back:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local Touching = false
local Part = script.Parent.Parent
--local Zone = ZonePlus.new(Part)
Part.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent.Parent:FindFirstChild("Humanoid")
if Humanoid and not Touching then
Touching = true
local HumanoidRootPart = Hit.Parent.Parent:WaitForChild("HumanoidRootPart")
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Name = "SlipVelocity"
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * -12
BodyVelocity.Parent = HumanoidRootPart
end
end)
Part.TouchEnded:Connect(function(Hit)
local Player = Players:GetPlayerFromCharacter(Hit.Parent.Parent)
if Player then
for _, v in pairs(Player.Character:GetDescendants()) do
if v:IsA("BodyVelocity") and v.Name == "SlipVelocity" then
v:Destroy()
Touching = false
end
end
end
end)
and by slip i mean when you get on another players head, it moves you back, and its impossible to move forward on their head
use the Touched event of the head part and check if the touching object is a player. Then, you can use the FindFirstChild method to check if the touching object has a Humanoid child, indicating that it’s a player character. You can then get the player instance using the Players:GetPlayerFromCharacter method and apply any effects to that player only.