-
What do you want to achieve? Make a physgun-like tool
-
What is the issue? I don’t know what I could do to have a line coming out from the tip of the tool that connects to the object in front and allows to move it around
-
What solutions have you tried so far? I searched about something similar to the Gmod’s physgun but I couldn’t find nothing
Firstly I would get the player’s mouse by using a localscript, I would use mouse.target method to get the object that the mouse is on then use mouse.hit to get the position the player wants to drag the object towards (make sure to exclude the object so it doesn’t glitch out), then send this to a server-sided script using remote-events.
Second, implement a input method that detects when the mouse is pressed down (and is kept down) and when the mouse is released (mouse keypress up) it releases the object, you can also unanchor the object if you want it to fall (do this serversided) and then anchor the object after it’s CFrame is not changed for like 1-2 seconds (this means the object is in a state that has no more momentum.
Thirdly, secure the positions, I would implement a distance limit to which the object can be dragged to (I would calculate this on the server end to prevent hackers/exploiters from messing around with the distance)
Finally comes the visual effects such as the line that you mentioned coming out from the tip of the tool that connects to the objects, I would use attachments and a beam, you can learn more here: Beams | Documentation - Roblox Creator Hub
Thank you so much! I will try that
Hi, I have a question (also, my apologies for replying so many days later), could you provide to me a starting script or something that I could use to start scripting this tool?
I really haven’t used Mouse.Hit nor things like limiting distances, etc.
Thank you in advance
local tool = script.Parent
local player = nil
tool.Equipped:Connect(function()
player = game.Players:FindFirstChild(tostring(tool.Parent.Name))
end)
tool.Activated:Connect(function()
if player == nil then
return warn("Player was not found.")
end
local mouse = player:GetMouse()
mouse.TargetFilter = {} -- Add instances to the list if they have to be ignored by the mouse (Note: the player's character is automatically ignored)
local target = mouse.Target
-- You can fire a remote event to the server so the server handles the target and checks if this is possible for the player to actually "reach it"
-- You can send the mouse object as well
local position_of_where_mouse_is_at = mouse.Hit.Position --You can use this to get the position of the mouse
-- Reminder: Make sure to check if the values ARE possible due to exploiters, etc. can send false information, which it is important to check the possibility of the values being true by a server script
end)
Note: This is a localscript under a tool.
For limiting the distance, it is needed to use raycast or something like that?