Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This even won't fire?

Asked by 10 years ago

I've got this tool going that I retrofitted from a HopperBin. In theory, and by all known laws of RBX.Lua, this script should work, unless I'm overlooking something. The script is below; I've done my best to document it.

s = false --This tells if the tool is selected, used to stop updatePos()

function onSelected(mouse) --Should fire when mouse is selected
    print ("selected")
    s = true --Indicates that the mouse is selected
    t = Instance.new("Part") --From here until line 15 it makes the part
    t.Anchored = true
    t.FormFactor = 2
    t.BottomSurface = "Smooth"
    t.TopSurface = "Smooth"
    t.BrickColor = BrickColor.new(Color3.new(math.random(0,1), math.random(0,1), math.random(0,1)))
    t.Transparency = 0.3
    t.Position = mouse.Hit.p --This is corrected in updatePos()
    t.Size = Vector3.new(4, 0.2, 4)
    t.Parent = game.Workspace
    repeat updatePos(t, mouse) until s == false --Will repeat updatePos() until unselected
    t:Destroy() --Removes part after unselected, as the loop won't run this code until it is done
end

function onDeselected() --Fires when deselcted, destroys the part...
    s = false
end

function updatePos(object, pos) --This one updates the part's position to corespond with the mouse's position, corrected to the nearest stud
    object.Position = Vector3.new(math.ceil(pos.Hit.x), object.Size.Y/2, math.ceil(pos.Hit.z))
    wait(0.0001)
end

script.Parent.Equipped:connect(onSelected) --Fires when equipped
script.Parent.Unequipped:connect(onDeselected) --Fires when unequipped

This script (in HopperBin form) worked exactly as it was supposed to. There are no errors thrown with this, and nothing from here appears in the output.

3 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Tools require a "Handle" part (a Part named Handle parented inside the tool) in order to work (apparently).

I just tested; the script runs fine if you have the handle, and does nothing if you do not. This is probably the problem and absolutely is poor behavior on ROBLOX's part.

This is an irrelevant suggestion, but I suggest that you round the position rather than use ceiling, so that the part ends up more centered!

0
Worked! Thanks! cheweydog 20 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Since the script is in a HopperBin, these events won't work:

script.Parent.Equipped:connect(onSelected)
script.Parent.Unequipped:connect(onDeselected)

Those events only correspond to Tools. Tools aren't HopperBins. They're two completely seperate things. The only similarity is that both are in the backpack. The correct events to use are these:

script.Parent.Selected:connect(onSelected)
script.Parent.Deselected:connect(onDeselected)

I hope this helped!

*Note: For more information on HopperBins, click here: HopperBins

Log in to vote
-2
Answered by
Asirix 15
10 years ago

Try getting rid of "s = false" at the beginning?

Also, I'm not sure, but aren't you suppose to indicate what "mouse" is?

Answer this question