Hello, I have been working on a little project laterly and I made a gravity gun, but now the issue is you can pick up other players which is not what I want. I do not want to search for humanoid because I want you to be able to pick up NPC’s. Is there another solution? The one I use now some how bypasses and still lets you pick up the other player. Thanks.
local isPlayer = game.Players:GetPlayerFromCharacter(heldObject.Parent)
If you don’t want to pick up any player you could just add something like this:
function IsPlayer(Char) -- Returns True Or False
local player = game.Players:GetPlayerFromCharacter(Char)
if player then
return true
end
return false
end
--Usage --
if not IsPlayer(char) then
return
end
----------
Or you could try something like this though it would have more lag and does the same thing.
function IsPlayer(Char) -- Returns True Or False
local player = nil
for i,p in pairs(game.Players:GetChildren()) do
if p.Name == Char.Name then
local PlrChar = p.Character or p.CharacterAdded:Wait()
if PlrChar == Char then
player = p
end
end
end
if player then
return true
end
return false
end
--Usage --
if not IsPlayer(char) then
return
end
Though this does the same thing so I recommend the first way.
Thanks I think it works, although its not working in studio since for some reason the players arent being added to the folder but looks like its going to work. Thanks
So I tried out my other weld gun and it seems not to work lol, then like the gravity gun. I still have mouse.TargetFilter = game.Workspace:WaitForChild(“Players”) but im still able to weld the player to an object.