Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do you make a tool be able to get only if ur close to it?

so i have this script that gets a tool in to a players inventory when a player clicks 'h' what i want to do is make the player be able to use that only when he is close to an item and i want the tool to dissapear after a player has clicked 'h' here is what ive made

local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key) Key = Key:lower() if Key == 'h' then local copy = game.Workspace.Tool:Clone()

copy.Parent = game.Players.LocalPlayer.Backpack end end)

1 answer

You would need to use magnitude for that.

something like this (Im at school, so i cant test to see if it works or nah :P):

local Player = game.Players.LocalPlayer 
local Mouse = Player:GetMouse()
Mouse.KeyDown:connect(function(Key) Key = Key:lower() if Key == 'h' then
local mt = Mouse.Target
local mh = Mouse.Hit.p
if (mh-Player.Character.HumanoidRootPart.Position).magnitude <= 10 then
if mt.ClassName == ("Tool") then
mt:Clone()
mt.Parent = game.Players.LocalPlayer.Backpack 
mt:Remove()
end 
end
end
end)

7 comments

0

¸thx for awnsering almost every one of my q

0

some thing is wrong with if mh-player... it sais Players.JollyDumb.PlayerGui.LocalScript:10: bad argument #2 to '?' (Vector3 expected, got number) 17:25:42.843 - Stack Begin

0

i mean it sais Players.JollyDumb.PlayerGui.LocalScript:10: bad argument #2 to '?' (Vector3 expected, got Object)

0

Does it work up until then? I would try adding prints in between some lines to see how far it goes.

0

ok i ll do it

0

i did the print thing and it looks like the problem is in line 4

0

i mean 6 not 4

This discussion is preserved as it was. New answers, comments, and votes are closed.