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

How do I make it so that my localscript tool only works when equipped?

Asked by 7 years ago

I have a tool to make you levitate upwards in a localscript in a filtering not enabled game, but you don't need to equip the tool to levitate when you click. How do I make it so that you do?

This is the script.


local Character = game.Players.LocalPlayer.character local TorPos = Character.HumanoidRootPart.Position local Player = game.Players.LocalPlayer local HumRoot = Character.HumanoidRootPart local Mouse = Player:GetMouse() local MystSkill = script.Parent.Mysticism.Value local LevHeight = Vector3.new(0,.5*MystSkill,0) script.Parent.Equipped:connect() local Levitating = false function levitate() if Levitating == false then Levitating = true local BodyPos = Instance.new("BodyPosition") BodyPos.Parent = Character.HumanoidRootPart while Levitating == true do BodyPos.Position = HumRoot.Position + LevHeight wait(.000001) end BodyPos:Destroy() end end function SetLevFalse() Levitating = false end function PrintPos() print(HumRoot.Position) print("MystSkill", .5%MystSkill) end Mouse.Button1Down:connect(levitate) Mouse.Button1Up:connect(SetLevFalse) Mouse.Button2Down:connect(PrintPos)
0
Tool.Activated would do what you want. Fires the signal when MB1 is clicked, only when the tool is equipped. RubenKan 3615 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Umm you can use the Equipped event.

Ex.

local tool = script.Parent.Parent
local party = script.Parent

tool.Equipped:connect(function()
    party.BrickColor = BrickColor.new("Really Red")
end)

tool.Activated:connect(function()
    print 'Hi'
end)

^^ This is a simple and easy script but, the use of the Equipped event makes it so that when equipped, the part changes color. Just use .Equipped: for equipping and .Unequipped for well, I guess you can figure that out.

If this doesn't help, then sorry.

0
Well, yes, that would work if I wanted it to just be active the entire time it's equipped... But is there a way to make it so that it can make the player float when clicked, but only if equipped? Kato12345 17 — 7y
0
Idk what you mean. Can you be more clear to what you exactly need? TheLightningRises 56 — 7y
0
Nevermind, I just realised that I am an idiot. I set it so that when an object is equipped a boolean is set to true, and before the script does anything it checks for that boolean. Thank you! I probably would not have thought of this if you hadn't posted your answer. Kato12345 17 — 7y
Ad

Answer this question