Hello!
I need help for with my code.
In my code, I anchor the HumanoidRootPart, and after anchoring it, I see its CFrame with CFrame.lookAt(), but as you can see (in the video below), it seems to “roll back” and move the character to older position. I really don’t understand why it does that.
Since it fires a high amount of events for that, I tried to just fire 1 event, but it did not solve the problem!
Here are the important piece of code:
Client Side:
UIS.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.E then
if UIS:IsKeyDown(Enum.KeyCode.E) then
local charge = 0
repeat
local mousepos = game.Players.LocalPlayer:GetMouse().Hit.p
if charge < 5 then
charge += .05
end
chargingEvent:FireServer(charge, "Water", "WaterBall", mousepos)
task.wait()
until UIS:IsKeyDown(Enum.KeyCode.E) and UIS:IsKeyDown(Enum.KeyCode.One) or input.UserInputState == Enum.UserInputState.End
end
end
end
end)
Server Side:
charge.OnServerEvent:Connect(function(plr, charge, art, attack, mousepos)
if art == "Water" then
if attack == "WaterBall" then
charging = true
print("Received")
local name = plr.Name.."Folder"
local sphere = rp.Abilities.Water.Ball
if not workspace:WaitForChild(name):FindFirstChild("Ball") then
local chargeSphere = sphere:Clone()
if workspace:FindFirstChild(name) then
if chargeSphere then
chargeSphere.Parent = workspace:FindFirstChild(name)
chargeSphere.Transparency = .5
end
end
end
local chargeSphere = workspace:FindFirstChild(name):WaitForChild("Ball")
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
hrp.Anchored = true
hrp.CFrame = CFrame.lookAt(hrp.Position, mousepos, Vector3.new(0,1,0))
chargeSphere.Size = Vector3.new(charge+1, charge+1, charge+1)
chargeSphere.CFrame = hrp.CFrame * CFrame.new(0,0,-5)
chargeSphere.Anchored = true
wait()
end
end
end)