Probably I couldn’t write the title very understandable, sorry for it. I’m not a native English speaker and this is my best.
I’m trying to make a tool and I want it to have a velocity on the same way with camera look. I already have a script for camera that locks the camera when tool is equipped.
Also I find CFrames very confusing so if it’s a basic thing, sorry for it.
I have a Vector3.new(0,0,100)
as a placeholder for velocity.
My 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
-- 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)
gui.Text = "Reloading"
local dots = 0
for i = 0, 8 do
value.Value = i
if dots <= 3 then
dots = dots + 1
else
gui.Text = "Reloading"
dots = 0
end
gui.Text = (gui.Text..".")
wait(0.7)
end
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 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 = Vector3.new(0,0,100)
Debris:AddItem(copyTool, 3)
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
print("reload")
star.Transparency = 0
db = false
end
else
dbReload = true
reload(ammoGui,ammo)
end
end)
tool.Unequipped:Connect(function()
copyGui:Destroy()
idleAnim:Stop()
end)
end)