I plan to create a screen GUI in the starter GUI that has a script, textbutton, and frame (the textbutton and frame being grouped together) that can add the tool to your inventory when you click on the button, and it is removed when you click again on the same textbutton. When I test the game, it doesn't do anything (AKA, it just sits there being able to be clicked, but the script wasn't functioning). I can tell that there are mistakes, but where are they, and how can I fix them? Here's the script:
local plr = game.Players.LocalPlayer
local tools = plr.Backpack
local Tool = game.Lighting.Sword
Player = script.Parent.Parent.Parent.Parent
function Remove()
if tools:FindFirstChild("Sword") then
tools.Tool:Destroy()
wait()
end
end
function Add()
if game.Lighting:FindFirstChild("Sword") then
Tool = game.Lighting.Tool:clone()
Tool.Parent=Player.Backpack
wait()
end
end
script.Parent.MouseButton1Down:connect(function()
if Player.Backpack:FindFirstChild("Sword") then
Remove()
else
Add()
end
end)
If you couldn't understand the way I set my screen GUI up, here's the link to the game:
https://www.roblox.com/games/4390322172/Scripting-help-demo-for-mistake

1 comment
Thank you for the approach. I will see what I can do with it.