-
What do you want to achieve?
I want the magnitude to work fine, wherever the player stands (close to the water) -
What is the issue?
The issue is that I don not know whether there is a formula or anything so I can actually have the magnitude working, the script works perfectly fine, just the player distance is a little messed up. E.g if I stand close to the water where the spawn is, the magnitude is different than let’s say 200 studs away, causing the animal(player) to drink even if it’s a little further away from water which ofc is unrealistic.
local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local Event = game.ReplicatedStorage.Events
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local character = player.Character
local hrp = character.HumanoidRootPart
local water = workspace.Water
local debounce = true
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=11892081628"
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.E and debounce then
if Mouse.Target ~= nil then
if Mouse.Target:FindFirstChild("Drinkable") then
if character then
hrp = character:WaitForChild("HumanoidRootPart")
local Position = hrp.Position
local magnitude = (water.Position - Position).Magnitude
print(magnitude)
if magnitude < 200 then
debounce = false
local playAnim = humanoid:LoadAnimation(anim)
humanoid.WalkSpeed = 0
playAnim:Play()
wait(2)
humanoid.WalkSpeed = 3.4
debounce = true
local Object = Mouse.Target
if Object.Drinkable.Value ~= false and Object.Transparency == 1 then
Event.Drink:FireServer(Object, false)
wait(1)
end
end
end
end
end
end
end)
Therefore, it’s difficult to set a certain magnitude, the red dots show an example value of magnitude.