Hello. I am currently using a free material to learn more about scripting a combat and I am having problem with this one thing.
Holding:GetPropertyChangedSignal("Value"):Connect(function()
if Holding.Value ~= "None" then
HumRP.Anchored = true
isHolding = true
if Holding.Value == "Z" then
Animations.Z:Play()
Animations.Z:GetMarkerReachedSignal("Idle"):Connect(function()
if isHolding == true then
Animations.Z:AdjustSpeed(0)
end
end)
repeat
HumRP.CFrame = CFrame.lookAt(HumRP.Position, Mouse:GetHit().Position)
task.wait()
until Holding.Value ~= "Z"
else
HumRP.Anchored = false
end
end)
As you can see, this script anchors the player when Z button is held down and makes the character turn its face to the mouse location. However this is a local script and is only visible to local player. I tried to turn this into a server script using a RemoteEvent. Here is what I have done:
Local script:
holding:GetPropertyChangedSignal("Value"):Connect(function()
if holding.Value ~= "None" then
humRP.Anchored = true
if holding.Value == "Z" then
repeat
rotateRemote:FireServer(mouse.Hit.Position)
task.wait()
until holding.Value ~= "Z"
end
else
humRP.Anchored = false
end
end)
Server script:
local RS = game:GetService("ReplicatedStorage")
local remote = RS.Remotes.holdRotateEmote
remote.OnServerEvent:Connect(function(player, mouse)
local char = player.Character
local HRP = char:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.lookAt(HRP.Position, mouse) task.wait()
end)
When I immediately hold Z right after jumping, the character teleports. Here is a gif to explain it better:
Gyazo
How can I do this better? Thanks in advance.