Hello, I am asking how can I send Mouse.Hit inputs to server scripts. So, I'm trying to make grappling, but it only prints out my string that I put in and doesn't put the attachment inside of the Mouse.Hit.Parent. P.S the grappling needs to go towards the mouse. I have both a localscript and server script.
--Localscript local mouse = game.Players.LocalPlayer:GetMouse() local player = game.Players.LocalPlayer local char = player.Character local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then game.ReplicatedStorage.RightGrapple:FireServer(char, mouse) end end)
--Script game.ReplicatedStorage.RightGrapple.OnServerEvent:Connect(function(char, mouse) local grappleright = coroutine.create(function() print("weeee we go on hook yey") local attachment = Instance.new("Attachment",mouse.Hit.Parent) attachment.Position = mouse.Hit local magichookthing = char.magixx.Welds.RightContainer:FindFirstChild("magichook") local rope = Instance.new("RopeConstraint",magichookthing) rope.Attachment0 = magichookthing.Attachment rope.Attachment1 = attachment end) coroutine.resume(grappleright) end)
The help would be appreciated, thanks!
You can't send the mouse to the server, because the raycasting going on is client sided only, so it is a simple fix, just send the mouse.Hit from the client to the server:
local script: (please do this outside of your script, I didn't know you had 2 code blocks until I went to view the source)
local mouse = game.Players.LocalPlayer:GetMouse() local player = game.Players.LocalPlayer local char = player.Character local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then game.ReplicatedStorage.RightGrapple:FireServer(char, mouse.Hit) end end)
Server script:
game.ReplicatedStorage.RightGrapple.OnServerEvent:Connect(function(char, Hit) print("weeee we go on hook yey") local attachment = Instance.new("Attachment") attachment.Parent = Hit local magichookthing = char.magixx.Welds.RightContainer:FindFirstChild("magichook") local rope = Instance.new("RopeConstraint") rope.Attachment0 = magichookthing.Attachment rope.Attachment1 = attachment rope.Parent = magichookthing --set parent last --you don't need a coroutine. end)
Since this answers your question, mark it as accepted.