I’m attempting to create an interaction where when one player pushes, it causes the other player to move in the direction the local player is facing.
tool.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= tool.Parent then
if Debounce == true and playershit[hit.Parent] == nil then
local Player = game.Players:GetPlayerFromCharacter(tool.Parent)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(16)
hit.Parent:FindFirstChild("Humanoid").PlatformStand = true
local att = Instance.new("Attachment")
att.Parent = hit
local linear = Instance.new("VectorForce")
linear.Parent = hit
linear.Attachment0 = att
linear.Force = Player.Character.HumanoidRootPart.CFrame.lookVector * 110
linear.RelativeTo = Enum.ActuatorRelativeTo.World
playRandomSound(hit, sounds)
randomdecal(hit, bruises)
playershit[hit.Parent] = true
task.wait(1)
hit.Parent:FindFirstChild("Humanoid").PlatformStand = false
playershit[hit.Parent] = nil
end
end
end)
Alright, please note this code is for example purposes only and doesn’t work, and wont achieve the results you are looking for its just written to give you an example
The tool’s hierarchy:
The ServerManager’s code
local tool = script.Parent
local lookvectorevent = tool:WaitForChild("Pushed")
lookvectorevent.OnServerEvent:Connect(function(plr,lookvector)
if lookvector then
plr.Character.HumanoidRootPart.AssemblyLinearVelocity = lookvector*10000 -- I know this will only work on the client, I am just providing this as an example because I did not code it to push other players
end
end)
The ClientManager’s code
local camera = workspace.CurrentCamera
local pusher = script.Parent:WaitForChild("Pushed")
local tool = script.Parent
local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(inputdata)
if inputdata.UserInputType == Enum.UserInputType.MouseButton1 or inputdata.UserInputType == Enum.UserInputType.Touch and tool.Parent:IsA("Model") then -- You could also just use Tool.Activated, I just like to use UIS for some reason
local lookvector = cam.CFrame.LookVector
if lookvector then
pusher:FireServer(lookvector)
end
end
end)