Hello. I’ve recently started working on a game, and have made some decent progress in it. However, I’ve run into a problem. Right now I’m programming the script for the attacks, and I’m trying to change the orientation of a part to point to the position of the mouse. Here’s the part:
I want it to point in a specific direction.
I’m having trouble with this though, because although the position of the part changes, the orientation doesn’t. Here’s my script:
Weird. Still not working. Here’s my entire script:
local rs = game.ReplicatedStorage
local event = rs.AttackEvents.Hydrogen.HydrogenShardEvent
local ts = game:GetService("TweenService")
local shardSpeed = 36
local damage = 20
event.Event:Connect(function(plr, char, mousepos)
local shard = rs.AttackResources.HydrogenShard.Parts.HydrogenShard:Clone()
shard.Parent = game.Workspace
shard.Position = char.HumanoidRootPart.Position
shard.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, mousepos.Position)
local info = TweenInfo.new(((shard.Position - mousepos.Position).Magnitude / shardSpeed),
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut, 0, false, 0)
local properties = { Position = mousepos.Position }
local tween = ts:Create(shard, info, properties)
tween:Play()
tween.Completed:Connect(function()
if shard then
shard:Destroy()
end
end)
local connection
connection = shard.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local o_char = hit.Parent
if o_char.Name ~= plr.Name then
shard:Destroy()
if o_char.Humanoid.Health - damage <= 0 then
connection:Disconnect()
o_char.Humanoid.Health = 0
-- tell death script about the death
else
connection:Disconnect()
o_char.Humanoid.Health -= damage
end
-- add damage gui
end
end
end)
end)
local rs = game.ReplicatedStorage
local event = rs.AttackEvents.Hydrogen.HydrogenShardEvent
local ts = game:GetService("TweenService")
local shardSpeed = 36
local damage = 20
event.Event:Connect(function(plr, char, mousepos)
local shard = rs.AttackResources.HydrogenShard.Parts.HydrogenShard:Clone()
shard.Parent = game.Workspace
shard.Position = char.HumanoidRootPart.Position
shard.CFrame = CFrame.lookAt(shard.Position, mousepos.Position)
local info = TweenInfo.new(((shard.Position - mousepos.Position).Magnitude / shardSpeed),
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut, 0, false, 0)
local properties = { Position = mousepos.Position }
local tween = ts:Create(shard, info, properties)
tween:Play()
tween.Completed:Connect(function()
if shard then
shard:Destroy()
end
end)
local connection
connection = shard.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local o_char = hit.Parent
if o_char.Name ~= plr.Name then
shard:Destroy()
if o_char.Humanoid.Health - damage <= 0 then
connection:Disconnect()
o_char.Humanoid.Health = 0
-- tell death script about the death
else
connection:Disconnect()
o_char.Humanoid.Health -= damage
end
-- add damage gui
end
end
end)
end)