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

Part Detecting Script Not Working?

Asked by 7 years ago

Problem: The output does not print anything, therefore something is wrong, it is a local script

local Player = game.Players.LocalPlayer
local Person = Player.Character.Torso.Position
local Water = game.Workspace.Water1.Position
local button = script.Parent


button.MouseButton1Down:connect(function()

if (Person - Water).magnitude <= 40 then 
     print('He is near waffles') 
 end

end)

1 answer

Log in to vote
0
Answered by 7 years ago

You have the idea. Im not sure if this is a LocalScript or not.. But I can edit it if you need! :)

local Player        =game.Players.LocalPlayer
local Torso         =workspace:WaitForChild(Player.Name).Torso
local Water         =workspace:WaitForChild("Water1")
local Button        =script.Parent -- a TextButton or something

function gPos()
    return({ Torso.Position; Water.Position })
end

Button.MouseButton1Click:connect(function()
    local pos=gPos()
     local gp1,gp2=pos[1],pos[2]
    if gp1~=nil and gp2~=nil then
        if ((gp1-gp2).magnitude) <= 40 then
            print(Player.Name.. " is near the waffles")
        end
    end
end)
Ad

Answer this question