I have a tool is starter player, i want to add magic to it when you have it equipped and you press E it uses ice magic, but instead you can use the magic as long as you have it in your inventory

local plr = game.Players.LocalPlayer --gets the player from the playerlist
local char = plr.CharacterAdded:Wait() --gets the character
local hum = char:WaitForChild("Humanoid") --gets the humanoid
local animation = hum:LoadAnimation(script:WaitForChild("Animation"))
local mouse = plr:GetMouse() --gets the mouse and all the functions you can do with it
local debounce = false --the cooldown variable
local equipped = script.Parent.Equipped

mouse.KeyDown:Connect(function(key) --if a key has been pressed
	if debounce == true then return end -- if the cooldown is active then stop the function
	if equipped and key == "e" then 
		debounce = true --cooldown active!
		animation:Play()
		wait(0.6) -- waits for the animation
		script.mountainfunc:FireServer() --fires a function called mountainfunc in the script
		wait(5.6) --the cooldown
		debounce = false 
	end
end)

and the animation isn't affecting the players right arm when it is equipped

2 comments

0

Just a tip. Scripts run in the player's backpack. So you'll have to disconnect the KeyDown event whenever the player unequips the tool.

0

For more information about disconnecting, read here: https://developer.roblox.com/en-us/articles/events