-
Hello, i am making a shooting game and its getting really far.
-
The problem is that am trying to do a script where players touch a part, the tool is disabled, and when the player leaves the part, the tools are avaiable for the player.
-
If someone can help me i would be really gratefull.
This is the script:
local Part = game.Workspace.TouchedSaveZone -- when is touched
local function on_part_touched(part, otherPart)
--looking for player
if otherPart.Parent:IsA("Model") and otherPart.Parent:FindFirstChild("Humanoid") then
--search for player
local player = otherPart.Parent.Parent
-- Disable tool
player.Backpack:FindFirstChild(Guns):Destroy()
end
end
Part.Touched:Connect(on_part_touched) -- touched ended
local function on_part_touch_ended(part, otherPart)
-- Check if the other part is a player character
if otherPart.Parent:IsA("Model") and otherPart.Parent:FindFirstChild("Humanoid") then
-- Get the player object
local player = otherPart.Parent.Parent
-- Give the player a tool
local tool = Instance.new("Tool")
tool.Name = Guns
tool.Parent = player.Backpack
end
end
Part.TouchEnded:Connect(on_part_touch_ended())