I am trying to tween an item, but it won’t work.
Here’s my script:
local ReplicatedStorage =game:GetService("ReplicatedStorage")
local fireThrow = ReplicatedStorage.FireThrow
local TweenService = game:GetService("TweenService")
fireThrow.OnServerEvent:Connect(function(plr,target)
local char = plr.Character or plr.Character:Wait()
local ball = char.Dodgeball
local handle = ball.Handle
if not ball then
return nil
end
if ball then
local prismLengths = {
length = handle.Position.X - target.X,
width = handle.Position.Z - target.Z,
height = handle.Position.Y - target.Y
}
for i, v in pairs(prismLengths) do
if v < 0 then
if i == 1 then
v = target.X - handle.Position.X
elseif i == 2 then
v = target.Z - handle.Position.Z
else
v = target.Y - handle.Position.Y
end
end
end
local c = math.sqrt(prismLengths.length^2 + prismLengths.width^2)
local d = math.sqrt(c^2 + prismLengths.height^2)
if d < 50 then
local pos = handle.Position
ball.Parent = game.Workspace
handle.Anchored = true
handle.Position = pos
local info = TweenInfo.new(
d/5,
Enum.EasingStyle.Circular,
Enum.EasingDirection.In,
0,
false
)
local goal = {}
goal.Position = Vector3.new(target.X, target.Y, target.Z)
local tween = TweenService:Create(handle, info, goal)
handle.Anchored = false
end
end
end)
This is the client script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireThrow = ReplicatedStorage.FireThrow
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local target = mouse.Hit.Position
local part = mouse.Target
local char = part.Parent
local hum = char:FindFirstChild("Humanoid")
if hum then
local plr = Players:GetPlayerFromCharacter(char)
if plr.Team ~= localPlayer.Team then
fireThrow:FireServer(target)
end
else
fireThrow:FireServer(target)
end
end
end)
The problem is that when I click somewhere with the item equipped, it leaves my inventory, but it doesn’t tween. How do I fix this?