hi, I am creating a script of the tool and I have a problem, I want the GUI of the tool to be clickable and can also be activated by an input key, but when I go to test it, the game does not give me errors and the first time that I take the tool, both methods are done, but when I unequip the tool and equip it again, the key doesn’t run, but the click yes. Can anyone help me?
--Here there are the codes of the Animations
local holdAnim = number
local Animation2 = number
--MainCore, here there are all the parts dedicated to the player and the GUI
local player = game.Players.LocalPlayer
local GUI = script.Parent:WaitForChild("AppleGUI", 1)
local LocalPlayer = game.Players.LocalPlayer
local Tool = script.Parent
local humanoid = player.Character:WaitForChild("Humanoid")
--KeyButtons
local UIS = game:GetService("UserInputService")
--Idle Animation
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://" .. holdAnim
local IdleAnimation = LocalPlayer.Character.Humanoid:LoadAnimation(anim)
--Animation1
local anim2 = Instance.new("Animation")
anim2.AnimationId = "rbxassetid://" .. Animation2
local SecondAnimation = LocalPlayer.Character.Humanoid:LoadAnimation(anim2)
--Sounds
local EatSound = script.Parent.Sounds.Eat
--Button
--local Button = player.PlayerGui:FindFirstChild("AppleGUI"):FindFirstChild("Animation2Mobile"):FindFirstChild("Button")
--local Button = player.PlayerGui:WaitForChild("AppleGUI", 1).Animation2Mobile.Point
local Debounce = false
local DebounceA = false
local DebounceB = false
--Script
Tool.Equipped:connect(function()
IdleAnimation:Play()
GUI:Clone().Parent = player.PlayerGui
player.PlayerGui:FindFirstChild("AppleGUI"):FindFirstChild("Animation2Mobile"):FindFirstChild("Button").MouseButton1Down:Connect(function()
local Button1 = player.PlayerGui:FindFirstChild("AppleGUI"):FindFirstChild("Animation2Mobile"):FindFirstChild("Button").Top
local Button2 = player.PlayerGui:FindFirstChild("AppleGUI"):FindFirstChild("Animation2Mobile"):FindFirstChild("Button").Bottom
if DebounceA == false then
IdleAnimation:Stop()
SecondAnimation:Play()
EatSound:Play()
Button1.BackgroundColor3 = Color3.new(0.407843, 0.407843, 0.407843)
Button2.BackgroundColor3 = Color3.new(255,255,0)
DebounceA = true
else
IdleAnimation:Play()
SecondAnimation:Stop()
EatSound:Stop()
Button1.BackgroundColor3 = Color3.new(255,255,0)
Button2.BackgroundColor3 = Color3.new(0.407843, 0.407843, 0.407843)
DebounceA = false
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
local Button1 = player.PlayerGui:FindFirstChild("AppleGUI"):WaitForChild("Animation2Mobile", 1):WaitForChild("Button", 1).Top
local Button2 = player.PlayerGui:FindFirstChild("AppleGUI"):WaitForChild("Animation2Mobile", 1):WaitForChild("Button", 1).Bottom
if DebounceA == false then
IdleAnimation:Stop()
SecondAnimation:Play()
EatSound:Play()
Button1.BackgroundColor3 = Color3.new(0.407843, 0.407843, 0.407843)
Button2.BackgroundColor3 = Color3.new(255,255,0)
DebounceA = true
else
IdleAnimation:Play()
SecondAnimation:Stop()
EatSound:Stop()
Button1.BackgroundColor3 = Color3.new(255,255,0)
Button2.BackgroundColor3 = Color3.new(0.407843, 0.407843, 0.407843)
DebounceA = false
end
end
end)
end)
Tool.Unequipped:connect(function()
player.PlayerGui:WaitForChild("AppleGUI"):Destroy()
IdleAnimation:Stop()
SecondAnimation:Stop()
EatSound:Stop()
Debounce = false
DebounceA = false
end)
Tool.Changed:Connect(function()
if Tool.Parent == player.Backpack then
IdleAnimation:Stop()
SecondAnimation:Stop()
EatSound:Stop()
end
end)