Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ServerStorage = game:GetService("ServerStorage")
- local Tool = ServerStorage:WaitForChild("PEWPEW")
- local Zone = workspace:WaitForChild("WeaponZone")
- -- Keep track of who has the tool
- local playersWithTool = {}
- Zone.Touched:Connect(function(hit)
- local character = hit.Parent
- local player = Players:GetPlayerFromCharacter(character)
- if player and not playersWithTool[player] then
- -- Give the tool
- local toolClone = Tool:Clone()
- toolClone.Parent = player.Backpack
- playersWithTool[player] = toolClone
- end
- end)
- Zone.TouchEnded:Connect(function(hit)
- local character = hit.Parent
- local player = Players:GetPlayerFromCharacter(character)
- if player and playersWithTool[player] then
- -- Remove the tool
- local tool = playersWithTool[player]
- if tool and tool.Parent then
- tool:Destroy()
- end
- playersWithTool[player] = nil
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement