function module.cast(origin, endposition, velocity, player, damage)
--ORIGIN IS A POSITION VARIABLE DONT DO origin.Position JUST DO origin
local Bullet = Instance.new("Part")
Bullet.Name = player.Name.."s bullet"
Bullet.Size = Vector3.new(1, 1, 5)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Color = Color3.new(1, 0.901961, 0.137255)
Bullet.Material = Enum.Material.Neon
Bullet.Parent = game.Workspace.CosmeticBullets
Bullet.CFrame = CFrame.new(origin, endposition)
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
Bullet.CFrame *= CFrame.new(0, 0, -velocity * (dt * 60))
if (Bullet.Position - origin).magnitude > 5000 then
Bullet:Destroy()
Loop:Disconnect()
end
end)
local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * velocity * 1.5)
if Hit then
local BulletHole = Instance.new("Part")
BulletHole.Parent = Hit.Instance
BulletHole.CFrame = CFrame.new(endposition, origin)
BulletHole.Anchored = true
Bullet.Size = Vector3.new(1, 1, 1)
if Hit.Instance.Parent:FindFirstChild("Humanoid") and damage ~= nil then
damage:FireServer(Hit.Instance.Parent, 10)
else
Loop:Disconnect()
Bullet:Destroy()
end
end
end
Ah, you have to put the Raycast inside the Loop like this:
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
Bullet.CFrame *= CFrame.new(0, 0, -velocity * (dt * 60))
if (Bullet.Position - origin).magnitude > 5000 then
Bullet:Destroy()
Loop:Disconnect()
end
local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * velocity * 1.5)
if Hit then
local BulletHole = Instance.new("Part")
BulletHole.Parent = Hit.Instance
BulletHole.CFrame = CFrame.new(endposition, origin)
BulletHole.Anchored = true
Bullet.Size = Vector3.new(1, 1, 1)
if Hit.Instance.Parent:FindFirstChild("Humanoid") and damage ~= nil then
damage:FireServer(Hit.Instance.Parent, 10)
else
Loop:Disconnect()
Bullet:Destroy()
end
end
end)
function module.aim(toaim,viewmodel,gun)
if toaim then
game:GetService('TweenService'):Create(game.ReplicatedStorage.Aim.AimValue, TweenInfo.new(1),{Value = 1}):Play()
else
game:GetService('TweenService'):Create(game.ReplicatedStorage.Aim.AimValue, TweenInfo.new(1),{Value = 0}):Play()
end
end
Hey, im not sure why it isnt tweening, ive just started doing the aiming, and I had triple checked this it looks the same as yours, but I’m not sure whats wrong, this is my code.(Also this is just as you start it and get the tween working)
local-
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsPlayerHoldingMouse = true
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
mainModule.aim(true, Viewmodel, GunModel)
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsPlayerHoldingMouse = false
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
mainModule.aim(false, Viewmodel, GunModel)
end
end)
module-
function module.aim(toaim, viewmodel, gun)
if toaim then
game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 1 }):Play()
gun.Components.Sight.CFrame = gun.Components.Sight.CFrame:Lerp(viewmodel.HumanoidRootPart.CFrame, game.ReplicatedStorage.Values.AimAlpha.Value)
else
game:GetService("TweenService"):Create(game.ReplicatedStorage.Values.AimAlpha, TweenInfo.new(1), { Value = 0 }):Play()
gun.Components.Sight.CFrame = gun.Components.Sight.CFrame:Lerp(viewmodel.HumanoidRootPart.CFrame, game.ReplicatedStorage.Values.AimAlpha.Value)
end
end