Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont these functions run on button press?

function poweron()
	if Enabled == false then
		game.Lighting.Aura:Clone().Parent = player.Torso
		player.Humanoid.WalkSpeed = 25
		local light = Instance.new("PointLight")
		light.Parent = player.Torso
		light.Brightness = 15
		light.Color = Color3.new(0, 255, 255)
		light.Range = 8
		Enabled = true
		end
end

function poweroff()
	if Enabled == true then
		player.Torso.light:Destroy()
		player.Torso.Aura:Destroy()
		player.Humanoid.WalkSpeed = 16
	end
end

function shoot()
	if Enabled == true then
		local d = player.Torso
		local newblast = blast:Clone()
		newblast.CFrame = tool.Parent.Torso.CFrame + (handle.Position - tool.Parent.Torso.Position).Unit * (handle.Position - tool.Parent.Torso.Position).Magnitude
			newblast.Velocity = (d.CFrame.lookVector * 180) + Vector3.new(math.random(-20, 20), 0, math.random(-20, 20))
			newblast.Touched:connect(BlastHit)
			newblast.Parent = game:GetService("Workspace")
			newblast.Blast:Play()
				
	end
end

function BlastHit(Part)
	if Part ~= nil and Part.Parent ~= nil and Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent ~= tool.Parent then
		Part.Parent.Humanoid:TakeDamage(37)
		Part.Parent.Humanoid.Jump = true
		wait(0.1)
		if tool.Parent:FindFirstChild("Torso") ~= nil then
			Part.Velocity = Part.Velocity + (tool.Parent.Torso.Position - Part.Position).Unit * 150
			tool.Parent.Torso.Velocity = (Part.Position - tool.Parent.Torso.Position).Unit * 200
		else
			Part.Velocity = Part.Velocity - Part.CFrame.lookVector * 120
		end
	end
end

function CheckKey(Key)
	if string.lower(Key) == "q" then
		poweron()
	elseif string.lower(Key) == "e" then
		poweroff()
	elseif string.lower(Key) == "f" then
		shoot(true)
	end
end

function ToolEquipped(Mouse)
	if Mouse == nil then
		return
	end
	Mouse.KeyDown:connect(CheckKey)
end
tool.Equipped:connect(ToolEquipped)

I started making a new tool earlier and this is part of this script I used. When I enter the game and press the button I assigned, it doesn't work....

1 answer

✓ Accepted answer

You are trying to use the mouse to read keyboard input?

Link to Mouse API

I would suggest that you use UserInputService to detect the key inputs.

I can also see other issues with this code but I suggest that you break up this code into tasks such as the shooting then test them individually so you know which part are working.

This discussion is preserved as it was. New answers, comments, and votes are closed.