Hello, my issue is as follows: I have a tool, and when I equip the tool, a JellyFishClone is spawned in the workspace and starts following me from behind. However, I tried to add a tween to make it move slightly up and down. But, while attempting to create this tween, it interferes with the movement of the JellyFishClone. How can I resolve this situation? I want it to both follow me and have a slight up-and-down movement with the tween.
Video:
Code:
local Tool = script.Parent
local Handle = Tool.Handle
local Jellyne = Instance.new("Model")
Jellyne.Name = "JellyFish"
local player = Tool.Parent.Parent
if player.Character then
player.Character:WaitForChild("Humanoid").Died:Connect(function()
if game.Workspace:FindFirstChild(player.Name.." JellyFish Handle") then
game.Workspace:FindFirstChild(player.Name.." JellyFish Handle"):Destroy()
end
end)
end
Tool.Equipped:Connect(function()
if not game.Workspace:FindFirstChild(player.Name.." JellyFish Handle") then
Tool.Enabled = false
vCharacter = Tool.Parent
myTorso = vCharacter:FindFirstChild("Torso") or vCharacter:FindFirstChild("UpperTorso")
myHumanoid = vCharacter:FindFirstChild("Humanoid")
playerName = myHumanoid.Parent
if myTorso == nil or myHumanoid == nil then
return
end
if Jellyne.Parent ~= nil and JellyneClone then
local target = myHumanoid.TargetPoint
local direction = (target - JellyneClone.Position).unit
else
JellyneClone = Handle:Clone()
JellyneClone.Name = "JellyFish"
JellyneClone.Parent = Jellyne
local floatForce = Instance.new("BodyForce")
floatForce.force = Vector3.new(0, getMassOfObject(Tool) * workspace.Gravity, 0)
floatForce.Name = "Float"
floatForce.Parent = JellyneClone
local bv = Instance.new("BodyVelocity")
bv.Name = "FollowBV"
bv.Parent = JellyneClone
bv.maxForce = Vector3.new(50000, 50000, 50000)
bv.P = 50000
Jellyne.Parent = workspace -- Değişiklik: Parent'ı workspace olarak ayarlandı
Jellyne.Name = playerName.Name.." JellyFish Handle" -- Değişiklik: Modelin adı değiştirildi
Jellyne:MoveTo(myTorso.Position + myTorso.CFrame.lookVector * 5.0)
setTransparency(1)
coroutine.resume(coroutine.create(follow))
end
end
end)
function getMassOfObject(obj)
local children
local mass = 0
if type(obj) == "userdata" then
children = obj:GetChildren()
elseif type(obj) == "table" then
children = obj
end
if children then
for i = 1, #children do
if children[i]:IsA("BasePart") then
mass = mass + children[i]:GetMass()
end
if #children[i]:GetChildren() > 1 then
mass = mass + getMassOfObject(children[i])
end
end
end
return mass
end
function setTransparency(value)
if value == nil then value = 0 end
Handle.Transparency = value
local children = Handle:GetChildren()
for i = 1, #children do
if children[i] and children[i]:IsA("BasePart") then
children[i].Transparency = value
end
end
end
function follow()
local bv = JellyneClone:FindFirstChild("FollowBV")
local stopped = false
while wait() do
local distance = (myTorso.Position - JellyneClone.Position).magnitude
if distance > 5.0 then
stopped = false
JellyneClone.CFrame = CFrame.new(JellyneClone.Position, myTorso.Position + Vector3.new(0, JellyneClone.Position.Y - myTorso.Position.Y, 0))
if distance > 8.0 then
bv.velocity = (myTorso.Position - JellyneClone.Position).unit * 20.0 + Vector3.new(0, 2, 0)
else
bv.velocity = (myTorso.Position - JellyneClone.Position).unit * 20.0 * (distance/24) + Vector3.new(0, 2, 0)
end
else
if not stopped then
stopped = true
bv.velocity = Vector3.new(0, 0, 0)
JellyneClone.Velocity = Vector3.new(0, 0, 0)
end
end
end
end