Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this not detecting that the player is not in range?

Asked by
tjtorin 172
5 years ago

This is supposed to print something when the player is hovering over a certain item and within 10 studs and it definitely does print but it does not matter how far the player is for some reason.

local m = require(workspace:WaitForChild("Modules"):WaitForChild("MainModule"))
local RunService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local char = workspace:WaitForChild(player.Name)
local Mouse = player:GetMouse()

RunService.RenderStepped:Connect(function()
    local target = Mouse.Target
    if target:FindFirstChild("CanHarvest") then
        if target:FindFirstChild("CanHarvest") then
            if char.UpperTorso.Position.X - target.Position.X > -10 or char.UpperTorso.Position.X - target.Position.X < 10 then
                if char.UpperTorso.Position.Z - target.Position.Z > -10 or char.UpperTorso.Position.Z - target.Position.Z < 10 then
                    print("ITS WORKING! (Maybe)")
                    m.overTarget = true                    
                end
            end
        else
            m.overTarget = false
        end
    else
        m.overTarget = false
    end
end)
0
okay i did not read ur script but ill write something similar to what ur asking for TheluaBanana 946 — 5y
0
ps pls arrange it TheluaBanana 946 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago

place this in StarterPack or something; unless if u have already solved it

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:connect(function()
    local target = mouse.Target

    if target:FindFirstChild("CanHarvest") ~= nil and (player.Character.HumanoidRootPart.Position - target.Position).magnitude < 10 then
        print("yey")
    end
end)
0
23 lines yo.... TheluaBanana 946 — 5y
Ad

Answer this question