generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Detection

Previous Thread :: Next Thread 
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 11:50 AM
Is there a way i can detect if there is a model within x studs of the character?
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
08 Mar 2015 11:58 AM
Magnitude.
http://wiki.roblox.com/index.php?title=Magnitude



"I like to program." - Bosswalrus
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:16 PM
Ok, i gert that but how can i detect wether there is another mdoel within a certain magnitude?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:22 PM
COuld i create a table of all the characters in the workspace then say while true do and constantly be checking to see if the magnitude of another character is less than 200?
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
08 Mar 2015 12:24 PM
local part=workspace.Part
for _,v in pairs(game.Players:GetChildren())do
if v.Character:FindFirstChild('Torso') then
if (v.Character.Torso.Position-part.Position).Magnitude < 200 then

end
end
end
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:26 PM
How can i then print that magnitude? i tried

local part=workspace.Part
for _,v in pairs(game.Players:GetChildren())do
if v.Character:FindFirstChild('Torso') then
if (v.Character.Torso.Position-part.Position).Magnitude < 200 then
print(v.Character.Torso.Position-part.Position).Magnitude)
end
end
end
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:28 PM
Or more to the point, how could i draw a raycast between the part and the char that went near it
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
08 Mar 2015 12:29 PM
You have to constantly search the workspace and run the function.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:30 PM
Ok i have a script which displays the magniute, btu now how can i draw a rtyacast?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 12:46 PM
Done


--while wait(3) do
--local part1 = script.Parent
--local part2 = script.Parent.Parent.Part2

--local magnitude = (part1.Position - part2.Position).magnitude
--if magnitude < 200 then
----print(magnitude)
--end
--end

local part=workspace.Part

while wait(1) do
for _,v in pairs(game.Players:GetChildren())do
if v.Character:FindFirstChild('Torso') then
local magnitude = v.Character.Torso.Position-part.Position
if magnitude.Magnitude < 200 then
print(magnitude.Magnitude)
local ray = Ray.new(part.Position, (v.Character.Torso.Position - part.Position))
local hit, position = game.Workspace:FindPartOnRay(ray, part)

local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end

local distance = (position - part.Position).magnitude
local rayPart = Instance.new("Part", game.Workspace)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position,part.Position) * CFrame.new(0, 0, -distance/2)

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 5)

end
end
end
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image