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

?Still a little confused about running these functions

I recently asked a questions about why my functions in the script of my tool wouldn't run on button press. The person who answered my first question told me to run my functions individually and my functions wont even run on Activated() I'm not sure if there's an error in my variables, or my code. Here is the entire code from what I have so far.

tool = script.Parent
player = tool.Parent
handle = tool.Handle
blastsound = handle.Blast
blast = Instance.new("Part")
blast.Name = "ElectricBall"
blast.BrickColor = BrickColor.new("Cyan")
blast.Material = "Neon"
blast.FormFactor = "Custom"
blast.Size = Vector3.new(4, 4, 4)
blast.TopSurface = "Smooth"
blast.BottomSurface = "Smooth"
blast.Locked = true
blast.CanCollide = false
blastsound:Clone().Parent = blast
blast.Blast.Volume = 1
Lift = Instance.new("BodyForce")
Lift.force = Vector3.new(0, blast:GetMass() *196.25, 0)
Lift.Parent = blast
game.Lighting.Lightning:Clone().Parent = blast
Enabled = false
Damaging = false

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(40)
		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

How would I go about running the functions on button press while the tool is equipped?

1 answer

✓ Accepted answer

If you want something to run at botton press while the tool is equipped. Simply use UserInputService.

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