Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- toolHandler script:
- local re = Instance.new("RemoteEvent")
- re.Parent = game:GetService("ReplicatedStorage")
- re.Name = "toolEvent"
- re.OnServerEvent:Connect(function(plr, tool)
- local mag = (tool:WaitForChild("Handle").Position - plr.Character.HumanoidRootPart.Position).magnitude
- if mag < 5 then
- tool.Parent = plr.Backpack
- end
- end)
- function untouch(list)
- for i = 1, #list do
- local handle = list[i]:WaitForChild("Handle")
- if handle then
- local ti = handle:FindFirstChild("antiTouch") -- <
- if not ti then
- local clone = script.antiTouch:Clone() -- <
- clone.Parent = handle
- clone.Disabled = false
- end
- end
- end
- end
- local tools = workspace:WaitForChild("tools"):GetChildren()
- untouch(tools)
- workspace.tools.ChildAdded:Connect(function(child)
- untouch({child})
- end)
- workspace.ChildAdded:Connect(function(child)
- if child:IsA("Tool") then
- wait()
- child.Parent = workspace.tools
- end
- end)
- antiTouch Script:
- local ti = script.Parent:FindFirstChild("TouchInterest")
- if ti then
- ti:Destroy()
- end
- script.Parent.ChildAdded:Connect(function(child)
- if child:IsA("TouchTransmitter") then
- wait()
- child:Destroy()
- end
- end)
- toolScript:
- local uis = game:GetService("UserInputService")
- local rs = game:GetService("ReplicatedStorage")
- local event = rs:WaitForChild("toolEvent") -- <
- local plr = game.Players.LocalPlayer
- local kg = plr.PlayerGui:WaitForChild("keyGui")
- local char = plr.Character
- function search()
- local tools = workspace:WaitForChild("tools"):GetChildren()
- local min = nil
- local tool = nil
- for i = 1, #tools do
- local handle = tools[i]:FindFirstChild("Handle")
- if handle then
- local mag = (char.HumanoidRootPart.Position-handle.Position).magnitude
- if min == nil or mag < min then
- min = mag
- tool = tools[i]
- end
- end
- end
- if min then
- if min < 5 then
- return tool
- end
- end
- end
- uis.InputBegan:Connect(function(input, gameProcessed)
- if input.UserInputType.Name == "Keyboard" and gameProcessed == false then
- if input.KeyCode.Name == "E" then
- local tool = search()
- if tool then
- event:FireServer(tool)
- kg.E.Visible = false
- end
- end
- end
- end)
- while wait(1) do
- local tool = search()
- if tool then
- kg.E.Visible = true
- else
- kg.E.Visible = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement