Hello everyone, I’m making a gear which character needs to throw but it doesn’t work properly.
It always gives velocity to wrong direction.
This is what happens:
Camera script has these offsets:
local WORLD_OFFSET = Vector3.new(0, 2, 0)
local LOCAL_OFFSET = Vector3.new(3, -2, 9.5)
Tool script:
-- Variables
local tool = script.Parent
local star = tool.Handle
local ammoGuiFull = tool.Ammo
local ammo = star.Ammo
local maxAmmo = 8
local db = false
local dbReload = false
local coolDown = 2
-- Services
local Debris = game:GetService("Debris")
-- Anims
local anims = {
R6 = "4976367520";
R15 = "4976399108"
}
local idleAnims = {
R6 = "4981140834";
R15 = "4981158126"
}
-- Functions
function createAnim(char,AnimID)
local hum = char:FindFirstChild("Humanoid")
if not hum:FindFirstChild("StarAnim") then
local animation = Instance.new("Animation")
animation.Name = "StarAnim"
animation.AnimationId = "http://www.roblox.com/Asset?ID="..AnimID
local loadedanim = hum:LoadAnimation(animation)
loadedanim:Play()
return loadedanim
end
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function reload(gui, value)
db = true
gui.Text = "Reloading"
local dots = 0
for i = 0, 8 do
value.Value = i
if dots < 3 then
dots = dots + 1
gui.Text = gui.Text.."."
else
gui.Text = "Reloading"
dots = 0
end
wait(0.7)
end
gui.Text = "8"
db = false
dbReload = false
end
-- Tool
tool.Equipped:Connect(function()
local char = script.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
local copyGui = ammoGuiFull:Clone()
copyGui.Parent = player.PlayerGui
local ammoGui = copyGui.Frame.ammo
ammoGui.Text = ammo.Value
local idleAnim
if hum.RigType == Enum.HumanoidRigType.R6 then
idleAnim = createAnim(char, idleAnims.R6)
else
idleAnim = createAnim(char, idleAnims.R15)
end
tool.Activated:Connect(function()
if ammo.Value > 0 then
if not db and not dbReload then
db = true
if hum.RigType == Enum.HumanoidRigType.R6 then
createAnim(char, anims.R6)
else
createAnim(char, anims.R15)
end
local copyTool = star:Clone()
star.Transparency = 1
copyTool.Velocity = (-workspace.CurrentCamera.CFrame.LookVector - Vector3.new(3,-2,9.5).Unit) * 50
copyTool.CanCollide = true
Debris:AddItem(copyTool, coolDown)
copyTool.Parent = workspace
ammo.Value = ammo.Value - 1
ammoGui.Text = ammo.Value
copyTool.Touched:Connect(function(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") then
local hum0 = hit.Parent:FindFirstChild("Humanoid")
local model = hum0.Parent
local damage = 20
if hum0.Parent ~= char then
if not copyTool:FindFirstChild("Hitted"..model.Name) then
local hit0 = Instance.new("ObjectValue",copyTool)
hit0.Value = hum0
hit0.Name = "notHitted"
for _, v in pairs(copyTool:GetChildren()) do
if v:IsA("ObjectValue") then
if v.Value then
UntagHumanoid(hum0)
TagHumanoid(hum0, player)
v.Value:TakeDamage(damage)
hit0.Name = ("Hitted"..model.Name)
v.Value = nil
end
end
end
elseif copyTool:FindFirstChild("notHitted") then
wait()
end
end
end
end
end)
repeat wait() until copyTool.Parent == nil
star.Transparency = 0
db = false
end
else
if dbReload == false then
dbReload = true
reload(ammoGui,ammo)
end
end
end)
tool.Unequipped:Connect(function()
copyGui:Destroy()
idleAnim:Stop()
end)
end)