How would I make a player face another player? (VIDEO ATTACHED)

I want to spin my player to face another player once they use an ability on them.

Example video:

Current scripts:

local script

local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local fireevent = game.ReplicatedStorage.AbilityEvents.Ignis
local spell = false

player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"ignis") ~= nil and debounce == false and spell == false and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
		spell = true
	end
end)

mouse.Button1Down:Connect(function()
	local mousetarg = mouse.Target
	if mouse.Target:IsA("BasePart") then
		if mouse.Target.Parent:FindFirstChild("Humanoid") and debounce == false and spell == true and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
			debounce = true
			if (mousetarg.Position - root.Position).magnitude <25 and debounce == true then
				fireevent:FireServer(mousetarg)
				wait(15)
				spell = false
				debounce = false
				print("cooldown over!!")
			end
		end
	end
end)

server script

game.ReplicatedStorage.AbilityEvents.Sleep.OnServerEvent:Connect(function(Player, Mouse)
	local animation = script.Caster
	local loadedanim = Player.Character.Humanoid:LoadAnimation(animation)
	if Player:GetRankInGroup(11954854) >= 6 then
	loadedanim:Play()
		local person = game.Players:GetPlayerFromCharacter(Mouse.Parent)	
		wait(.5)
	
	game.ReplicatedStorage.Message:FireClient(person, "You have been put to sleep by "..Player.Name.."\nSweet dreams")
	Mouse.Parent.Humanoid.ragdoll.Value = true
	wait(20)
	Mouse.Parent.Humanoid.ragdoll.Value = false
	loadedanim:Stop()
	end
end)

aware that these scripts don’t match up.
i just want help on the spinning thing
all i need is the code, and which script to put it in

1 Like
character:SetPrimaryPartCFrame()

Also, be careful with that animation, self-harm isn’t allowed on Roblox.

it’s not my game. i just got the video from a discord server im in, and wanted to know how to do the spin thing

where do i put this?? what do i put in the brackets?

The mistake was that the player script and the server script were not matched up. The player script needed the code for the spinning, and the server script needed the code for the sleeping.

local script


local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local fireevent = game.ReplicatedStorage.AbilityEvents.Ignis
local spell = false

player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"ignis") ~= nil and debounce == false and spell == false and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
		spell = true
	end
end)

mouse.Button1Down:Connect(function()
	local mousetarg = mouse.Target
	if mouse.Target:IsA("BasePart") then
		if mouse.Target.Parent:FindFirstChild("Humanoid") and debounce == false and spell == true and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
			debounce = true
			if (mousetarg.Position - root.Position).magnitude <25 and debounce == true then
				fireevent:FireServer(mousetarg)
				wait(15)
				spell = false
				debounce = false
				print("cooldown over!!")
			end
		end
	end
end)

server script

game.ReplicatedStorage.AbilityEvents.Sleep.OnServerEvent:Connect(function(Player, Mouse)
	local animation = script.Caster
	local loadedanim = Player.Character.Humanoid:LoadAnimation(animation)
	if Player:GetRankInGroup(11954854) >= 6 then
	loadedanim:Play()
		local person = game.Players:GetPlayerFromCharacter(Mouse.Parent)	
		wait(.5)
	
	game.ReplicatedStorage.Message:FireClient(person, "You have been put to sleep by "..Player.Name.."\nSweet dreams")
	Mouse.Parent.Humanoid.ragdoll.Value = true
	wait(20)
	Mouse.Parent.Humanoid.ragdoll.Value = false
	loadedanim:Stop()
	end
end)

I coded both of your spinning animation and the server script.

i’m well aware the scripts do not match. i grabbed 2 random scripts from my game. I just want to know how to spin them and which script to put it in.

the animation is NOT the spin.

LOCAL SCRIPT

local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local fireevent = game.ReplicatedStorage.AbilityEvents.Ignis
local spell = false

player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"ignis") ~= nil and debounce == false and spell == false and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
		spell = true
	end
end)

mouse.Button1Down:Connect(function()
	local mousetarg = mouse.Target
	if mouse.Target:IsA("BasePart") then
		if mouse.Target.Parent:FindFirstChild("Humanoid") and debounce == false and spell == true and player.Character.Humanoid.ragdoll.Value == false and not player.Character.Humanoid.PlatformStand and player.Character.Humanoid.Health > 0 then
			debounce = true
			if (mousetarg.Position - root.Position).magnitude <25 and debounce == true then
				fireevent:FireServer(mousetarg)
				wait(15)
				spell = false
				debounce = false
				print("cooldown over!!")
			end
		end
	end
end)

Alright, maybe try this script it may work.

If this doesn’t work I sadly cannot help you.

Hey, if you still haven’t figured this out yet, what script (and where) do you want the player rotate code to be?

Normally, to rotate a player to face another object, or player in your case, you can do

CFrame.new(hrp.Position,Vector3.new(enemyhrp.Position.X,hrp.Position.Y,enemyhrp.Position.Z))

Since the second property of CFrame is a direction to look at, you can rotate the player’s CFrame by just the X and Z, so they don’t rotate facing down or up.

Hopefully this can be of some help haha. Goodluck!

3 Likes

Which script do I put this in? I’d prefer it if it was possible in the server script

Both scripts would work here! All you need is the player’s humanoidrootpart and the enemy’s humanoidrootpart. Here’s what i’m thinking…

local person = game.Players:GetPlayerFromCharacter(Mouse.Parent)
if person then
    local hrp = Player.Character:FindFirstChild("HumanoidRootPart")
    local enemyhrp = person.Character:FindFirstChild("HumanoidRootPart")
    if hrp and enemyhrp then
        hrp.CFrame = CFrame.new(hrp.Position,Vector3.new(enemyhrp.Position.X,hrp.Position.Y,enemyhrp.Position.Z))
    end
end

(I had to write this on the devForum, so it may not work haha. Give it a try anyways and let me know what happens.)

EDIT: If you want it to smoothly rotate, use TweenService!

1 Like

It worked! Thank you :slight_smile:
I do have a question though. I want it to rotate smoothly, so how would I use tweens for that?

this probably wont work but hopefully it’s along the right lines???

local goal = {hrp.CFrame = enemyhrp.CFrame}
local info = tweeninfo.new(2, enum.easingstyle.linear, enum.easingdirection.in)
tweenService:Create(hrp, info, goal)

Sorry for such a late reply, I forgot about this topic!

Yes, you’re looking into the right direction! But you’ve set a few things up wrong.

local goal = {hrp.CFrame = enemyhrp.CFrame}

Instead of referencing an objects properties, you need to reference a class. So:

local goal = {CFrame = CFrame.new(hrp.Position,Vector3.new(enemyhrp.Position.X,hrp.Position.Y,enemyhrp.Position.Z))}

Now, that should fix your issue! Just make sure to run :Play() after you make the tween, or after you assign it as a variable.

tweenService:Create(hrp, info, goal):Play()

or

local tween = tweenService:Create(hrp, info, goal)
tween:Play()

If you have any other questions let me know!

1 Like

Use a runservice connection, and use CFrame.LookAt() function heres an example of it

local examplePlayer = workspace.ExamplePlayer
local ExampleTarget = workspace.ExampleTarget
local Connection = nil
Connection = game:GetService("RunService").HeartBeat:Connect(function()
	examplePlayer.HumanoidRootPart.CFrame = CFrame.lookAt(
		Vector3.new(
			ExampleTarget.Position.X,
			examplePlayer.HumanoidRootPart.Y,
			ExampleTarget.Position.Z
		)
	)
end)



-- Disconnect the function
if Connection then 
	Connection:Disconnect()
	Connection = nil
end

There are others ways that are better but this is just an example

sorry for the very late response, i was in spain on a holiday

it doesn’t seem to work for me, and there’s nothing in output.

script:

(this is the server script, the one where i did the tween you said to do)

local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

game.ReplicatedStorage.AbilityEvents.Sleep.OnServerEvent:Connect(function(Player, Mouse)
	local animation = script.Caster
	local loadedanim = Player.Character.Humanoid:LoadAnimation(animation)
	if Player:GetRankInGroup(11954854) >= 6 then
		loadedanim:Play()
		local person = game.Players:GetPlayerFromCharacter(Mouse.Parent)	
		if person then
			local hrp = Player.Character:FindFirstChild("HumanoidRootPart")
			local enemyhrp = person.Character:FindFirstChild("HumanoidRootPart")
			if hrp and enemyhrp then
				local goal = {CFrame = CFrame.new(hrp.Position,Vector3.new(enemyhrp.Position.X,hrp.Position.Y,enemyhrp.Position.Z))}
			local yuh = TweenService:Create(hrp,info,goal)
				yuh:Play()
			wait(.5)
	game.ReplicatedStorage.Message:FireClient(person, "You have been put to sleep by "..Player.Name.."\nSweet dreams")
	Mouse.Parent.Humanoid.ragdoll.Value = true
	wait(20)
	Mouse.Parent.Humanoid.ragdoll.Value = false
	loadedanim:Stop()
			end
		end
		end
end)