I'm trying to make it where a fire spell only works if you have the wand equipped on your hand. However, after equipping and then unequipping, you still can use the fire spell. Does anyone have a fix for this?
Local Script
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local debounce = false
script.Parent.Equipped:Connect(function(player)
UIS.InputBegan:Connect(function(Input, IsTyping)
if not IsTyping then
if not debounce then
debounce = true
if Input.KeyCode == Enum.KeyCode.Z then
game.ReplicatedStorage.Fireball:FireServer(mouse.Hit.Position)
end
wait(0.1)
debounce = false
end
end
end)
end)
Script
local fireball = game.ServerStorage:WaitForChild("Fireball")
script.Parent.Equipped:Connect(function()
game.ReplicatedStorage.Fireball.OnServerEvent:Connect(function(player, mousePos)
local character = player.Character
local newFireball = fireball:Clone()
newFireball.Position = character.HumanoidRootPart.Position
newFireball.Parent = workspace
local velocity = Instance.new("BodyVelocity", newFireball)
velocity.Velocity = CFrame.new(newFireball.Position, mousePos).LookVector * 100
velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local touchConn
touchConn = newFireball.Touched:Connect(function(hit)
if hit == nil then return end
if hit.Parent.Name == player.Name then return end
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
if touchConn ~= nil then touchConn:Disconnect() end
newFireball:Destroy()
end
end)
wait(2)
if touchConn ~= nil then touchConn:Disconnect() end
newFireball:Destroy()
end)
end)

7 comments
Hello, I am here to help you out.
Thanks!
Maybe you should watch Alvinblox's video of the fireball?
This is different. Fireball works, its just that I only want the fireball to cast when I have the wand only equipped.
Is their any errors?
Just going to say that mouse can be obtained as an argument passed by the Equipped event of a tool
no errors.