So basically im trying to script a potion where if i press the R key my player will equip the potion and automatically start drinking it without me having to click. I have a script but im gonna be honest i don’t know what im doing so please feel free to tell me what im doing wrong or if im doing everything wrong.
Im just a builder trying to get into scripting (basic scripting)
local tool = script.Parent
local function toolEquipped()
tool.Handle.Equip:toolActivated()
end
local function toolActivated()
tool.Handle.Activate:toolActivated()
end
tool.Equipped:Connect(toolEquipped)
tool.Activated:Connect(toolActivated)
local tool = script.Parent.Pistol
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
tool.Activated:Connect(function()
print("Test") -- Do function work here, send connection to server with remote event if you want to replicate to server
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and player.Character then
local Hum = player.Character:WaitForChild("Humanoid")
Hum:EquipTool(tool)
wait()
tool:Activate()
end
end)