Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't the magnitude work at all?


local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local t = char.Torso

char.BSFolder.BallCount.Value = char.BSFolder.BallCount.Value + 1

local ball = Instance.new("Part")
ball.FormFactor = "Custom"
ball.Shape = "Ball"
ball.BottomSurface = "Smooth"
ball.TopSurface = "Smooth"
ball.CanCollide = false
ball.Size = Vector3.new(0.5,0.5,0.5)
ball.BrickColor = BrickColor.new("Really black")

local subject = Instance.new("Part")
subject.Parent = t
subject.FormFactor = "Custom"
subject.CanCollide = false
subject.Size = Vector3.new(0.1,0.1,0.1)
subject.BrickColor = BrickColor.new("Really black")
ball.Parent = subject

local w = Instance.new("ManualWeld")
w.Name = "Weldy"
w.Parent = subject
w.Part0 = t
w.Part1 = subject

w.C0 = CFrame.new(0,0,0)

local w2 = Instance.new("ManualWeld")
w2.Name = "Weldy"
w2.Parent = ball
w2.Part0 = subject
w2.Part1 = ball

w2.C0 = CFrame.new(0,0,2.7)


-- // 

for index, child in pairs(game:GetService("Players"):GetPlayers()) do
	if child.Name ~= plr.Name then
		
		print("Kappa1")
		
	if (ball.Position - child.Character.Torso.Position).magnitude < 10 then
		
		print("Kappa2")
		
	local ray = Ray.new(ball.Position - child.Character.Torso).unit * 10
	
	local ignore = game.Players.LocalPlayer.Character
	
	local hit, position, normal = workspace:FindPartOnRay(ray, ignore)
		
		end
	end
end




-- //





--==========================================

local angle = 0

while true do
	w.C0 = CFrame.new(0,0,0) * CFrame.Angles(0, angle, 0)
	wait()
	angle = angle + 0.1
end

--==========================================


I'm trying to get a raycast whenever a character that is not localplayer gets close to the "ball" part , which is rotating around the localplayer. And I can't get the magnitude to work.

5 comments

0

I'm assuming that it prints Kappa1?

0

It does.

0

Please provide some context to the problem and what errors you are getting and so forth. It's very confusing to everyone else because we don't know what we're trying to answer

0

There. I've specified what' s my issue.

0

If I helped, accept the answer so people know it's solved, por favor.

1 answer

✓ Accepted answer
local ray = Ray.new(ball.Position - child.Character.Torso).unit * 10

You're missing an 'origin' argument and a parenthesis. I'm not sure where you want the origin to be, but it will be in this format;

local ray = Ray.new(origin, (ball.Position - child.Character.Torso).unit * 10)

Moreover, this won't cast a ray whenever someone comes close. It will check through the players once, and never again until the script runs again (if it's in StarterGui or StarterPack it will run when you respawn).

2 comments

0

Okay, so if I want the ball block be the origin I need to put ball.Position as origin ?

0

Yup

This discussion is preserved as it was. New answers, comments, and votes are closed.