Hello Devs, I’m working on a Power Slapping game. I’m currently trying to deal damage to the humanoid using the speed of the mouse as its colliding with the character. Instead of returning a actual number it just returns 0. I’m completely confused on why its doing this. Please Help.
Video
Client Code
-- Services --
local PlrService = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
-- Constants / Stuff --
local Character = script.Parent
local LocalPlr = PlrService:GetPlayerFromCharacter(Character)
local LocalMouse = LocalPlr:GetMouse()
-- Constants / Remotes --
local GameRemotes = ReplicatedStorage:FindFirstChild('GameRems')
local MainEvent = GameRemotes:FindFirstChild('MainEvent')
-- Constants / Numbers --
local LastPosition = Vector2.new(0,0)
local MouseSpeed = 0
local CanSlap = true
----
-- Functions --
local function FollowPart()
local Humanoid = Character:WaitForChild('Humanoid')
local Head = Character:WaitForChild('Head')
-- Check --
local Part = Instance.new('Part')
-- Setup Part --
Part.Name = 'FollowPart'
Part.Parent = Character
Part.Size = Vector3.new(1,1,1)
Part.Anchored = true
Part.CanCollide = false
Part.Position = Vector3.new(Head.Position.X,Head.Position.Y + 2,Head.CFrame.LookVector.Z + 10)
-- Setup IKControls --
Humanoid.ArmControl.Target = Part
Humanoid.TorsoControl.Target = Part
-- While Statement --
while CanSlap do
task.wait()
Part.Position = Vector3.new(LocalMouse.Hit.X,Part.Position.Y,Part.Position.Z)
-- Update Mouse --
MouseSpeed = math.floor((Vector2.new(LocalMouse.X,LocalMouse.Y) - LastPosition).Magnitude/50)
LastPosition = Vector2.new(LocalMouse.X,LocalMouse.Y)
end
end
----
-- OnClientEvent --
MainEvent.OnClientEvent:Connect(function(SentEvent)
-- Check --
if SentEvent == 'Touched Part' then
-- Update --
MainEvent:FireServer('MouseSpeed',MouseSpeed)
end
end)
----
-- Init --
FollowPart()
----
But if I toggle the comment on LastPosition = Vector2.new(LocalMouse.X,LocalMouse.Y) It returns a number higher than 0 but it gives me a horribly unrealistic number the mouse wasn’t even moving in.
I Added 2 TextLabels. One that labels the current Mouse Speed and one that labels what the mouse speed was when hit. But I’ve realized that its not really accurate (or I don’t think it is). Here’s a clip I took of it.
I calculate it from the Movement Speed Of The Mouse aka this line MouseSpeed = math.floor((Vector2.new(LocalMouse.X,LocalMouse.Y) - LastPosition).Magnitude/5)