I'm making my own SFOTH sword. It's a cloud sword and when someone touches it, it will float them up into the air.
Here's the script that makes it do that (some lines are completely useless, that was just me being desperate to make it work):
script.Parent.Handle.Touched:Connect(function(OtherPart) if OtherPart.Parent:FindFirstChild("Humanoid") then local T = OtherPart.Parent.Torso local Smoke = game.ServerStorage.Smoke:Clone() Smoke.Parent = T local TweenInfo1 = TweenInfo.new( 4, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0 ) local H = T.Parent.Head H.Anchored = true local Tween = game:GetService("TweenService"):Create(T.Parent.Head, TweenInfo1, {Position = Vector3.new(H.Position.X, H.Position.Y + 60, H.Position.Z)}) local Po = H.Position H.Position = Po Tween:Play() H.Position = Po wait(4) Smoke:Destroy() H.Anchored = false end end)
It works the first time when I touch a player. but the next time it sends them to a position around 30 studs away and launches them up from there. Any help?
Before I get to the solution, I'm going to go through your script and explain a few things you shouldn't do.
The first thing is in multiple instances there, you've referenced specific body parts of the Character that is being hit, and that would be fine if you are changing visual properties like Transparency or Color, or like what you did in the beginning with adding smoke to their Torso. However, when you want to change the position of the entire Character, it's a lot safer to use their HumanoidRootPart.
Next thing is that you are tweening the Character's Head's position, but when you move or teleport a Character, you almost always want to use the Character's HumanoidRootPart's CFrame.
Last thing is simply that you've got some completely useless lines (like 17 and 18) as you've already said. Including things like getting the Head from the Torso's parent instead of just making a variable for the Character and just doing something like char.Head
. Also this is just my opinion on keeping things organized, but creating objects like Smoke in ServerStorage without renaming it or putting it in a folder before using it is not a good practice, but it's not a problem if you keep it that way.
So now the solution:
--instantiate all unchanging variables outside of the event local info1 = TweenInfo.new( 4, Enum.EasingStyle.Quad, --you might want to change this if the float effect isn't exactly what you wanted Enum.EasingDirection.In, 0, false, 0 ) local Smoke = game.ServerStorage.Smoke -- a function for creating tweens local function tween(object,info,goals) return game:GetService("TweenService"):Create(object,info,goals) end script.Parent.Handle.Touched:Connect(function(OtherPart) if OtherPart.Parent:FindFirstChild("Humanoid") then local HRP = OtherPart.Parent.HumanoidRootPart Smoke:Clone().Parent = HRP HRP.Anchored = true local Pos = HRP.CFrame.Position local goal1 = { CFrame = CFrame.new(Pos.X,Pos.Y+60,Pos.Z) } local Tween = tween(HRP, info1, goal1) Tween:Play() wait(4) Smoke:Destroy() HRP.Anchored = false end end)
I put the smoke in the HumanoidRootPart because you will already be using it for doing the cloud effect, and the HumanoidRootPart is a transparent part centered on the torso, where the original smoke effect was held.