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

How would I go about altering this script to work with a Tool?

Originally, this script was meant to work with Hopperbins; but due to the last update, Hopperbins break the game. Also, since they've been deprecated for a while, it is time to switch to Tools.

Here's the Hopperbin version:

bin = script.Parent
blah = true

local hat = nil

function onButton1Down(mouse)
if blah == true then
blah = false
	local player = game.Players.LocalPlayer
	if player == nil then return end
	for _,m in ipairs(player.Character:GetDescendants()) do
	if m.Name == "effect" then
	m.Transparency = 0.33
	wait(0.01)
	m.Transparency = 0.67
	wait(0.01)
	m.Transparency = 1
	wait(15)
	m.Transparency = .99
	wait(0.01)
	m.Transparency = 0.67
	wait(0.01)
	m.Transparency = 0
	end
	end


	end
	wait(9)
blah = true
end

function onSelected(mouse)
	mouse.Icon = "rbxasset://textures\\ArrowCursor.png"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

bin.Selected:connect(onSelected)

Here is the Tool version attempt:

local Tool = script.Parent
local debounce = true

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
    if player == nil then return end
    for _,m in ipairs(player.Character:GetDescendants()) do
    if m.Name == "effect" then
        local d = m
local hat = nil

Tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()

if debounce == true then
debounce = false
    d.Transparency = 0.33
    wait(0.01)
    d.Transparency = 0.67
    wait(0.01)
    d.Transparency = 1
    wait(9)
    d.Transparency = .99
    wait(0.01)
    d.Transparency = 0.67
    wait(0.01)
    d.Transparency = 0

    end
    wait(9)
debounce = true
    end)
    end)
end
end

1 answer

Here, lets clean this up for you, to be clear the script you should be using is a localscript

local Tool = script.Parent
local debounce = true
local hat = nil
local hat = nil
local player = game.Players.LocalPlayer

local Mouse = player:GetMouse()


for _,m in ipairs(player.Character:GetDescendants()) do
	if m.Name == "effect" then
		local d = m
	end
end

function toolActivated()

	if debounce == true then
	
		d.Transparency = 0.33
		wait(0.01)
		d.Transparency = 0.67
		wait(0.01)
		d.Transparency = 1
		wait(9)
		d.Transparency = .99
		wait(0.01)
		d.Transparency = 0.67
		wait(0.01)
		d.Transparency = 0
		debounce = false

	end
	wait(9)
	debounce = true



Tool.Activated:connect(toolActivated)

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