Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
JollyDumb -21
7 years ago

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

Log in to vote
0
Answered by
Nikkulaos 229 Moderation Voter
7 years ago
Edited 7 years ago

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)
0
¸thx for awnsering almost every one of my q JollyDumb -21 — 7y
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 JollyDumb -21 — 7y
0
i mean it sais Players.JollyDumb.PlayerGui.LocalScript:10: bad argument #2 to '?' (Vector3 expected, got Object) JollyDumb -21 — 7y
0
Does it work up until then? I would try adding prints in between some lines to see how far it goes. Nikkulaos 229 — 7y
View all comments (3 more)
0
ok i ll do it JollyDumb -21 — 7y
0
i did the print thing and it looks like the problem is in line 4 JollyDumb -21 — 7y
0
i mean 6 not 4 JollyDumb -21 — 7y
Ad

Answer this question