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
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”
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})
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.