in the code I have right now, the "bolt" variable doesn't fire towards the mouse, and when I push "z" it faces the character the opposite direction it's currently facing. also, the debounce doesn't work. any ideas would help

player = game.Players.LocalPlayer
character = player.CharacterAdded:wait()
humanoid = character:WaitForChild('Humanoid')
mouse = player:GetMouse()
mousehit = mouse.hit
char = player.Character
hum = char.Humanoid
root = char.HumanoidRootPart

local Ready =  false

WaterBolt = Instance.new("Part", game.Workspace)
WaterBolt.Shape = "Ball"
WaterBolt.CanCollide = false
WaterBolt.Material = "Neon"
WaterBolt.BrickColor = BrickColor.new("Electric blue")
WaterBolt.Size = Vector3.new(3,3,3)

uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(input,gpe)
	if input.KeyCode == Enum.KeyCode.Z and Ready == false then
		Ready = true
		root.CFrame = CFrame.new(root.Position,root.Position + Vector3.new(mousehit.lookVector.x,0,mousehit.lookVector.z))
		wait(0.7)
		local bolt = WaterBolt:Clone()
		bolt.Parent = game.Workspace
		local bv = Instance.new("BodyVelocity")
		bv.MaxForce = Vector3.new(1e8,1e8,1e8)
		bv.Velocity = mousehit.lookVector*100
		bv.Parent = bolt
		
		bolt.Touched:connect(function(hit)
			local me = player
			if me then
				local hum1 = me:FindFirstChild("Humanoid")
				hum1:TakeDamage(0)
			else
				local hum2 = hit.Parent:FindFirstChild("Humanoid")
				hum2:TakeDamage(10)

				uis.InputEnded:connect(function(code)
					if code.KeyCode == Enum.KeyCode.Z then
						wait(5)
						Ready = false
						bolt:Destroy()						
					end
				end)
			end
		end)
	end
end)


5 comments

0

Why make a variable if you are only going to use it once?

0

if you're talking about the root variable i plan to use it later on, sorry

0

managed to fix the problem with the direction that the character is facing...debounce still wont work and ball doesnt go towards the mouse still though

0

I know how to do it

0

You can do if dbName == false then dbName == true --code here-- end wait()if dbName == true then dbName == false end