I have been stuck with this for a while. This is my newest script.
script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position, (mousePos - script.Parent.Handle.Position) * 300, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local hitPosition = raycastResult.Position
local attach = Instance.new("Attachment")
attach.CFrame = CFrame.new(hitPosition)
attach.Parent = hitPart
print("Hit Position:", hitPosition)
print("Attachment Position:", attach.WorldPosition)
local balloon = game.ReplicatedStorage.Balloon:Clone()
balloon.Parent = workspace
balloon:SetPrimaryPartCFrame(CFrame.new(hitPosition))
balloon.RopeConstraint.Attachment1 = attach
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
local humanoid = model:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(30)
end
end
end
end)
It works when i just click on the baseplate or something anchored but not when i click on something anchored. This the hit position and attachment position for an anchored part 06:56:39.499 Hit Position: -1.3556596040725708, 0, -10.056815147399902 - Server - Server2.0:16
06:56:39.499 Attachment Position: -1.3556596040725708, -10, -10.056815147399902 - Server - Server2.0:17 and here is an unanchored part 06:56:58.299 Hit Position: -29.928237915039062, 3.2020673751831055, -39.248931884765625 - Server - Server2.0:16
06:56:58.299 Attachment Position: -70.52479553222656, 11.900918960571289, -95.80228424072266 - Server - Server2.0:17
Can someone help me? What I want to accomplish is a gun and wherever you click/shoot an attachment will spawn/be created there and then I will attach a balloon to that attachment (I can do the balloon thing with a simple rope constraint) Any and all help is appreciated! It works when it is anchored but not on unanchored objects