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
6 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.

01local m = require(workspace:WaitForChild("Modules"):WaitForChild("MainModule"))
02local RunService = game:GetService("RunService")
03local player = game:GetService("Players").LocalPlayer
04local char = workspace:WaitForChild(player.Name)
05local Mouse = player:GetMouse()
06 
07RunService.RenderStepped:Connect(function()
08    local target = Mouse.Target
09    if target:FindFirstChild("CanHarvest") then
10        if target:FindFirstChild("CanHarvest") then
11            if char.UpperTorso.Position.X - target.Position.X > -10 or char.UpperTorso.Position.X - target.Position.X < 10 then
12                if char.UpperTorso.Position.Z - target.Position.Z > -10 or char.UpperTorso.Position.Z - target.Position.Z < 10 then
13                    print("ITS WORKING! (Maybe)")
14                    m.overTarget = true                   
15                end
View all 23 lines...
0
okay i did not read ur script but ill write something similar to what ur asking for TheluaBanana 946 — 6y
0
ps pls arrange it TheluaBanana 946 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago

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

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03 
04mouse.Move:connect(function()
05    local target = mouse.Target
06 
07    if target:FindFirstChild("CanHarvest") ~= nil and (player.Character.HumanoidRootPart.Position - target.Position).magnitude < 10 then
08        print("yey")
09    end
10end)
0
23 lines yo.... TheluaBanana 946 — 6y
Ad

Answer this question