I've tried literally everything and spent like 8 hours trying to rotate a projectile

I don’t know what to do this is getting on my nerves I spent 10 hours just trying to rotate a projectile when the character fires it but I don’t know how… Please, please help…

here’s the script:


--Rescripted by Luckymaxer

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")
Debris = game:GetService("Debris")

ProjectileScript = script:WaitForChild("ProjectileScript")

BasePart = Instance.new("Part")
BasePart.Shape = Enum.PartType.Block
BasePart.Material = Enum.Material.Plastic
BasePart.TopSurface = Enum.SurfaceType.Smooth
BasePart.BottomSurface = Enum.SurfaceType.Smooth
BasePart.FormFactor = Enum.FormFactor.Custom
BasePart.Size = Vector3.new(0.2, 0.2, 0.2)
BasePart.CanCollide = true
BasePart.Locked = true
BasePart.Anchored = false

BaseProjectile = BasePart:Clone()
arrowMesh = Instance.new("SpecialMesh")
arrowMesh.MeshId = "http://www.roblox.com/asset/?id=49925357"
arrowMesh.TextureId =  "http://www.roblox.com/asset/?id=49846927"
arrowMesh.Scale = Vector3.new(0.5, 0.5, 0.5)
arrowMesh.Parent = BaseProjectile

Grips = {
	Up = CFrame.new(0, -0.550000012, -0.649999976, 1, 0, -0, -0, 0.19592391, -0.980619073, 0, 0.980619192, 0.19592388),
	Out = CFrame.new(0, -0.550000012, -0.649999976, 1, 0, -0, 0, 0, -1, 0, 1, -0),
}

Sounds = {
	Equip = Handle:WaitForChild("Equip"),
	PewPew = Handle:WaitForChild("PewPew"),
	Hit = Handle:WaitForChild("Hit"),
}

ReloadTime = 0.1

ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
ServerControl.Name = "ServerControl"
ServerControl.Parent = Tool

ClientControl = (Tool:FindFirstChild("ClientControl") or Instance.new("RemoteFunction"))
ClientControl.Name = "ClientControl"
ClientControl.Parent = Tool

ToolEquipped = false

Tool.Grip = Grips.Out
Tool.Enabled = true

function Fire(Direction)

	local SpawnPos = (Handle.Position + (Direction * 10))

	local Gravity = 196.20
	local Force = 150

	local Mass = (BaseProjectile:GetMass() * Gravity)

	local Projectile = BaseProjectile:Clone()
	Projectile.CFrame = CFrame.new(SpawnPos)
	Projectile.Velocity = (Direction * Force)
	local HitSound = Sounds.Hit:Clone()
	HitSound.Parent = Projectile
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.maxForce = Vector3.new(Mass, Mass, Mass)	
	BodyVelocity.velocity = (Direction * Force)
	BodyVelocity.Parent = Projectile

	local CreatorTag = Instance.new("ObjectValue")
	CreatorTag.Value = Player
	CreatorTag.Name = "Creator"
	CreatorTag.Parent = Projectile

	local ProjectileScriptClone = ProjectileScript:Clone()
	ProjectileScriptClone.Disabled = false
	ProjectileScriptClone.Parent = Projectile

	Debris:AddItem(Projectile, 5)
	Projectile.Parent = game:GetService("Workspace")

	Sounds.PewPew:Play()

end

function Activated()
	if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
		return
	end

	local TargetPos = InvokeClient("MousePosition")
	if not TargetPos then
		return
	end
	TargetPos = TargetPos.Position
	local Direction = (TargetPos - Handle.Position).unit

	Tool.Enabled = false
	Tool.Grip = Grips.Up
	Fire(Direction)
	wait(ReloadTime)
	Tool.Grip = Grips.Out
	wait(ReloadTime)
	Tool.Enabled = true

end

function CheckIfAlive()
	return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0) and true) or false)
end

function Equipped()
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	if not CheckIfAlive() then
		return
	end
	ToolEquipped = true
	Sounds.Equip:Play()
end

function Unequipped()
	Tool.Grip = Grips.Out
	for i, v in pairs(Sounds) do
		v:Stop()
	end
	ToolEquipped = false
end

function InvokeClient(Mode, Value)
	local ClientReturn = nil
	pcall(function()
		ClientReturn = ClientControl:InvokeClient(Player, Mode, Value)
	end)
	return ClientReturn
end

ServerControl.OnServerInvoke = (function(player, Mode, Value)
	if player ~= Player or not ToolEquipped or not CheckIfAlive() or not Mode or not Value then
		return
	end
end)

Tool.Activated:connect(Activated)
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
1 Like
projectile.CFrame = CFrame.lookAt(projectile, mouse.Hit)

good luck

if the parts not anchored then do this

projectile.CFrame = CFrame.lookAt(projectile, mouse.Hit)

gyro = Instance.new("BodyGyro")
gyro.Parent = projectile
gyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
gyro .CFrame = CFrame.lookAt(projectile, mouse.Hit)

Where would I put that? Or it doesn’t matter also what is mouse.hit that’s not on my script

no mouse.Hit???
you cant make a functioning gun without that!

Unless, your gun is not going to be controlled by the mouse.

I don’t really know I’m trying to fix this where I was messing with a while ago so the position works it’s just the rotation it doesn’t move where the mouse is, or the camera I want it to rotate you can play test it in studio if you want and see what I mean

you only have to rotate the projectile when setting its CFrame.

Projectile.CFrame = CFrame.new(SpawnPos) * CFrame.Angles(0, math.pi/2, math.pi/2)

Here’s my solution for this, if the part isn’t anchored:

local turnSpeed = 2

game:GetService("RunService").RenderStepped:Connect(function(dt)
    projectile.CFrame *= CFrame.Angles(0, 0, math.rad(turnSpeed) * dt) -- assuming the projectiles lookvector is the direction it's moving
end)

It’s not a local script it’s a normal script.

Then use .Heartbeat. I misunderstood you for a second.

That doesn’t work I don’t know why here’s the model

you’re using a model? You cannot use this method with model, of course. use setpivot():

local turnSpeed = 2

game:GetService("RunService").Heartbeat:Connect(function(dt)
    projectile:SetPivot(projectile:GetPivot() * CFrame.Angles(0, 0, math.rad(turnSpeed) * dt)) -- assuming the projectiles lookvector is the direction it's moving
end)

try this

no take the tool out of the model

I don’t understand what that means?

Okay, so I’ve provided the model if you could take the model and insert it in your game when u insert it the tool will be inside of a model, just put the tool in starterpack and you’ll see what I’m talking about how the arrows don’t rotate.

I won’t insert anything into my game, but if you can send me images, and also clarify what type of instance you’re trying to rotate? A part or a model?

it’s a part I was only talking about the model that I’ve provided.

I just want them to face the right way when the player clicks also I’m talking about the “arrows”

Sorry, I forgot to apply the direction. It should work now

Projectile.CFrame = CFrame.lookAt(SpawnPos, SpawnPos + Direction) * CFrame.Angles(0, math.pi/2, math.pi/2)
1 Like