You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I am attempting to create a grapple hook system, and am currently trying to get a rope constraint to attach to whatever the mouse is pointing at.
- What is the issue? Include screenshots / videos if possible!
I have a system in place to create an attachment at where the mouse is pointed (using mouse.Hit/CFrame), and at the tip of the grapple shooter. The system then creates a rope constraint using both of said attachment points. For whatever odd reason, the second attachment point where the mouse lays is not correct.
Here is my code and a video of the issue:
LocalScript inside of StarterCharacterScripts
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local LAttach = char.ODM.LeftGrapple.LGrapple3.LRopeAttachment
local RAttach = char.ODM.RightGrapple.RGrapple3.RRopeAttachment
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
local mousehit = mouse.Target
local mousecf = mouse.Hit
game.ReplicatedStorage.RightOdm:FireServer(mousehit, mousecf)
end
end)
Server Script inside of ServerScriptService:
game.ReplicatedStorage.RightOdm.OnServerEvent:Connect(function(plr, hit, cf)
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local LAttach = char.ODM.LeftGrapple.LGrapple3.LRopeAttachment
local RAttach = char.ODM.RightGrapple.RGrapple3.RRopeAttachment
local lefttarget = Instance.new("Attachment")
lefttarget.Parent = hit
lefttarget.CFrame = cf
local leftrope = Instance.new("RopeConstraint")
leftrope.Parent = char.ODM.LeftGrapple.LGrapple3
leftrope.Color = BrickColor.new("Black")
leftrope.Thickness = 0.05
leftrope.Attachment0 = LAttach
leftrope.Attachment1 = lefttarget
leftrope.Length = math.abs((LAttach.WorldPosition - lefttarget.WorldPosition).Magnitude)
leftrope.Visible = true
end)
(upload://yrEnWnD3XsBh81RGYziZz8t86rs.mp4)
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I havenât found any similar problems with relevant answers through my own searches (though I am aware I may have missed something).
I have tried switching between declaring mouse.Hit and mouse.Target as variables and inside of the actual code itself, tried in both client and server sided scripts, and have tried position and cframe.