I made a script that is supposed to shoot a fireball when you right-click while holding the tool, but it doesnt work
How can I fix this? Am I missing something?
No Errors in the output either
local Tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local mouseButton = ""
UserInputService.InputBegan:Connect(function(input, gpe)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
mouseButton = "RIGHT"
Tool:Activate()
end
end)
Tool.Activated:Connect(function()
if mouseButton == "RIGHT" then
local remote = game.ReplicatedStorage.FireballEvent
remote.OnServerEvent:Connect(function(player, MousePosition)
local fireball = game.ReplicatedStorage.Fireball:Clone()
fireball.Parent = workspace
fireball.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
local NewForce = Instance.new("BodyForce")
NewForce.Force = Vector3.new(0, workspace.Gravity * fireball:GetMass(), 0)
NewForce.Parent = fireball
fireball.Velocity = CFrame.new(player.Character. HumanoidRootPart.Position, MousePosition).LookVector * 50
fireball. Touched:Connect(function(hit)
if hit. Parent:FindFirstChild ("Humanoid") and not hit:IsDescendantOf(player.Character) then hit.Parent:FindFirstChild ("Humanoid"): TakeDamage(50)
fireball:Destroy()
end
end)
end)
end
end)
Will someone please let me know! Thank you!