I made a script I'm very pleased with that fires an orb from a wand tip to the mouse location, but I noticed it also works with other tools out and no tool at all. Can I get a hint or some guidance as to how I can make sure that this script only runs when this tool is out? Thanks Immediately below is the hierarchy StarterWand(Tool) > Main(LocalScript) > MAIN(Script) and UseWand(RemoteEvent) StarterWand> Handle(Part) and Stick(Part)
Main:
wait (1.0) local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() function Clicked (mouse) script.UseWand:FireServer() end function ConnectFunction (mouse) Mouse.Button1Down:connect(Clicked) end script.Parent.Equipped:Connect(ConnectFunction)
MAIN:
local mouse = game.Players.LocalPlayer:GetMouse() -- allows us to see what the mouse is doing local debounce = false script.Parent.UseWand.OnServerEvent:Connect(function(Player) -- create a function for when the tool is used. No name needed for the function since it is called upon on a server event. if debounce == false then debounce = true wait(.5) local Orb = game.ReplicatedStorage.Small:Clone() -- create a part called orb that is exactly like the part in replicated storage called small Orb.CFrame = script.Parent.Parent.Handle.CFrame*CFrame.new(0 ,1.6, 0) -- give the orb a reference point to spawn from, this is at the origin of the handle Orb.Parent = game.Workspace -- make sure the part's parent is workspace so it is in the workspace local BV = Instance.new("BodyVelocity", Orb) -- give it a body velocity so that it may move BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- Give the body velocity a maximum force to not exceed BV.Velocity = (mouse.Hit.p - Orb.Position).unit * 65 -- velocity is position and speed so I have it a position, the players mouse and a speed of 65 local alreadytouched = false Orb.Touched:connect(function(hit) if alreadytouched == false then local human = hit.Parent:FindFirstChild("Humanoid") if human ~= nil and human.Parent ~= Player.Character then human:TakeDamage(10) alreadytouched = true end end end) wait (.5) debounce = false end end)
Please and thank you, I'm still learning :D
wait (0.25) local tool = script.Parent local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Active = false function Clicked (mouse) if Active == true then script.UseWand:FireServer() end end tool.Equipped:Connect(ConnectFunction) Active = true Mouse.Button1Down:Connect(function(Clicked) Clicked() end) end) tool.UnEquipped:Connect(function() Active = false end)