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

Tool Giver UI breaks when a player approaches with a tool equipped fix?

Asked by
vocful 6
5 years ago

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

01local debounce = false
02 
03function getPlayer(humanoid)
04local players = game.Players:children()
05for i = 1, #players do
06if players[i].Character.Humanoid == humanoid then return players[i] end
07end
08return nil
09end
10 
11function onTouch(part)
12 
13local human = part.Parent:findFirstChild("Humanoid")
14if (human ~= nil) and debounce == false then
15 
View all 30 lines...

Tool Giver GUI -local script

1local button = script.Parent
2local tool = game.ReplicatedStorage:WaitForChild("Mug")
3local plr = game.Players.LocalPlayer
4 
5button.MouseButton1Click:Connect(function()
6tool:Clone().Parent = plr.Backpack
7script.Parent.Parent.Parent.Enabled = false
8end)

Takes and Replaces Tools -local script

01local button = script.Parent
02local tool = game.Players.LocalPlayer.Backpack.Mug
03local plr = game.Players.LocalPlayer
04local new = game.ReplicatedStorage.Water
05 
06button.MouseButton1Click:Connect(function()
07    tool:Destroy()
08    new:Clone().Parent = game.Players.LocalPlayer.Backpack
09script.Parent.Parent.Parent.Enabled = false
10end)

CONCLUSION: How do I make it so the UI Tool Giver does NOT break when a player approaches with a tool equipped.

0
The problem is that you didnt use a remote event since the local player cannot give itself a tool. JesseSong 3916 — 5y

Answer this question