Tool Giver UI breaks when a player approaches with a tool equipped fix?
GOAL: A player touches a certain part to get a tool from a UI (activates when player touches part). Then they make their way to another location to change their tool (another UI), by removing the tool from their backpack and giving them a new one from ReplicatedStorage.
--Player touches a part, UI tool giver pop up and closes when player picks a tool. Player moves to touch another part to have another UI pop up. This new UI allows them to remove their old tool, giving them a new tool.
ISSUE: All works perfectly, the problem is when a player has a tool equipped when they touch the part, the UI breaks. It neither gives a tool nor closes.
Shows UI on Touch -script
03 | function getPlayer(humanoid) |
04 | local players = game.Players:children() |
06 | if players [ i ] .Character.Humanoid = = humanoid then return players [ i ] end |
13 | local human = part.Parent:findFirstChild( "Humanoid" ) |
14 | if (human ~ = nil ) and debounce = = false then |
18 | local player = getPlayer(human) |
20 | if (player = = nil ) then return end |
22 | script.Parent:clone().Parent = player.PlayerGui |
30 | script.Parent.Parent.Touched:connect(onTouch) |
Tool Giver GUI -local script
1 | local button = script.Parent |
2 | local tool = game.ReplicatedStorage:WaitForChild( "Mug" ) |
3 | local plr = game.Players.LocalPlayer |
5 | button.MouseButton 1 Click:Connect( function () |
6 | tool:Clone().Parent = plr.Backpack |
7 | script.Parent.Parent.Parent.Enabled = false |
Takes and Replaces Tools -local script
01 | local button = script.Parent |
02 | local tool = game.Players.LocalPlayer.Backpack.Mug |
03 | local plr = game.Players.LocalPlayer |
04 | local new = game.ReplicatedStorage.Water |
06 | button.MouseButton 1 Click:Connect( function () |
08 | new:Clone().Parent = game.Players.LocalPlayer.Backpack |
09 | script.Parent.Parent.Parent.Enabled = false |
CONCLUSION: How do I make it so the UI Tool Giver does NOT break when a player approaches with a tool equipped.