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
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.
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)
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!
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!
It worked! Thank you
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)
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
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)