How to check if two object's X axis values are the same?

Hello.

I am making a remake of the clown van kidnap script.

In that script, the van stops to pick you up and then leaves.

My question is, how do I make the van to stop doing the moving tween when it’s X axis value is the same as the victims?

I tried making the victim a parameter of the function and checking the values with if math.abs(primary.Position.X - victim.Position.X) < 0.1 then break end

without success.

You might have to stop the tween in the loop, not break the statement

1 Like

Hmm true.

However another problem is actually the victim variable itself. Since the victim variable would be defined later as the “victim of the command”, it doesnt identify it having an X value. Thus it returns “Attempt to index nil with X”

Then you probably shouldnt change the definition. Could you send the full script?

Module:

function vanmodule.movetovictim(victim)
	local tsinfo = TweenInfo.new(
		0.1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0
	)
	while task.wait(0.1) do
		local position = primary.CFrame
		local newposition = position + Vector3.new(1,0,0)
		local tween = ts:Create(primary, tsinfo, {CFrame = newposition})
		tween:Play()
		if (primary.Position.X - victim.Position.X).Magnitude < 0.1 then tween:Pause() end
	end
end	

Server script:

local instance = game.ReplicatedStorage.Van:Clone()
local modulescript = instance:WaitForChild("ModuleScript")
local primarypart = instance:WaitForChild("primary")

local module = require(modulescript)
instance.Parent = game.Workspace

if instance.Parent == game.Workspace then
	primarypart:SetNetworkOwner(nil)
	primarypart.Anchored = true
end
local target = workspace.AlreadyPro
module.movetovictim({victim = target})

these are the relevant parts.

sorry for the late reply but try redefining the victim value in the function

1 Like

I don’t get how I could get it to work, when i’m trying to get the victim players CFrame.

How do I get the victim’s CFrame as a variable in the function, when we don’t know the victims cframe yet? I tried with a parameter, but just says nil etc.

I got it to work. I found that using this to check would be better.

local playerroot = player.Character:FindFirstChild("HumanoidRootPart")
	if playerroot then
		vanmodule.movetovictim(primarypart, playerroot)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.