Hi, I need help making an alien UFO ship that abducts people. The code works kinda but the tweening is a bit glitchy here’s a video with my script and what is happening:
This is my script:
local Beam = script.Parent.Beam
local UFO = script.Parent.UFO
local debounce = false
Beam.Touched:Connect(function(hit)
wait(0.5)
local hum = hit.Parent:WaitForChild("Humanoid")
if hum then
if debounce == false then
debounce = true
local primary = hum.Parent:FindFirstChild("HumanoidRootPart")
local Info = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
local goal = {}
goal.CFrame = UFO.CFrame
local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(primary,Info,goal)
Tween:Play()
wait(5)
script.Parent.Humanoid:TakeDamage(200)
elseif debounce == true then
print("Nothing")
end
end
end)
What's my problem?
I did it without the wait and it still did it. My intensions of the wait is to try and make sure that it isn’t looping the tween for a few seconds. Clearly that didn’t work.
Anchor the HumanoidRootPart to stop that stuttering, its because physics and TweenService are colliding. TweenService involves no physics hence it goes against physics and it stutters. So, anchoring will prevent physics from acting on the player and you will be able to smoothly tween the position.
Here’s a script I have in my Yeah, steampunk... - Roblox place for the vertical ascent (or descent, just change the b.Position to wherever you want the player to go) tubes.
The script is in a button on the ground.
I have the game as R6 so you may want to change character.Torso to character.HumanoidRootPart.
function onTouched(hit)
local character = hit.Parent
if character and character:findFirstChild("Humanoid") then
local b = Instance.new("BodyPosition")
b.position = Vector3.new(-615.414, -320.017, 337.296)
b.maxForce = Vector3.new(3500, 9000, 3500)
b.D = 500
b.P = 1500
b.Parent = character.Torso
local g = Instance.new("BodyGyro")
wait(3)
b.Parent = nil
g.Parent = nil
end
end
script.Parent.Touched:connect(onTouched)
It works pretty smoothly, and if you change the D and P values you get a nice smooth acceleration and deceleration at the ends. You need to change the wait(3) time to whatever works best for your abduction ray.