mouse.Button1Down not detecting?

I’m looking to make it so that when a tool is equipped and the player clicks that a specified object is pulled from the sky and tweens itself to the clicked position.
The issue I’m having is that, while the output does print a “yes” and the “thrown first,” “thrown second” doesn’t appear in output.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local mouse = player:GetMouse()
local tweenserv = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(5)
local equipped = false

script.Parent.Equipped:Connect(function()
	equipped = true
	print("yes")
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
	print("no")
end)

mouse.Button1Down:Connect(function()
	print("thrown first")
	if equipped == true then
		print("thrown second")
		script.Parent.SendIt:FireServer(mouse.Hit.Position)
	end
end)

What am I doing wrong here? This is a localscript.

3 Likes

You should use script.Parent.Activated:Connect(function() instead.

3 Likes

I’ve tried that and “Thrown first” doesn’t even show if I do that

1 Like

Try printing (equipped) in the MouseButton1Click function.

Also try removing the == equality operator and true boolean:

To this:

if equipped then

I know it means the same thing but you could try that.

Doing that only revealed that my mouse1down isn’t even working, nothing is printing when I click. Tool.Activated doesn’t work either, where do I go from here??

Maybe try to convert the local script into a regular script. This has happened many times to me.

Code that would normally work wouldn’t work in a local script. However, when I transferred the code into a “normal” script, it just magically started to work.

I would try that but the issue is that I need to get the player’s mouse, I’m pretty sure I can only do that in a LocalScript, that’s the only reason I’m using a LocalScript.

Maybe try using the .Activated event in the Script instead of getting the mouse and detecting a click (Player:GetMouse() or UserInputService.InputBegan (not gonna write the rest but you prolly know)).

I’m pretty sure the .Activated event only really is detected in server scripts so that’s why it may have not been working in your local script.

I tried that, but .Activated doesn’t work. It doesn’t print anything at all.

Try something like this.

local Tool = script.Parent
local ObjectToSummon = game.Workspace.ObjectToSummon
local SummonHeight = 20
local SummonTime = 1.5

Tool.Activated:Connect(function()
    local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
    local Mouse = Player:GetMouse()
    local ClickPosition = Mouse.Hit.p

    local SummonedObject = ObjectToSummon:Clone()
    SummonedObject.Parent = game.Workspace
    SummonedObject.Position = Vector3.new(ClickPosition.x, ClickPosition.y + SummonHeight, ClickPosition.z)

    local ObjectTweenInfo = TweenInfo.new(SummonTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    local ObjectTween = game.TweenService:Create(SummonedObject, ObjectTweenInfo, {Position = ClickPosition})
    ObjectTween:Play()
end)

ServerScript inside of the Tool.

1 Like

You’ve tried it in a Server script? Not the Local Script that you’re currently hosting your tool’s code in.

Local Scripts and tools work to a small extent.

Also, I do understand you have a RemoteEvent. You might have to move that into a ModuleScript or into the tool’s script itself.

Just tried that, still nothing. I’ll try this other code that Rendered suggest though!

2 Likes

I tried this, and absolutely nothing- I had the suspicion that it was the .Activate and so I put a print and I was right- Nothing prints. Give me a second to grab a video.


Could it be the GUI? I can’t image so but- maybe??

Let’s try some debugging.

local Tool = script.Parent
local ObjectToSummon = game.Workspace.ObjectToSummon
local SummonHeight = 20
local SummonTime = 1.5

Tool.Activated:Connect(function()
    local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
    if not Player then
        return
    end

    local Mouse = Player:GetMouse()
    local ClickPosition = Mouse.Hit.p

    local SummonedObject = ObjectToSummon:Clone()
    SummonedObject.Parent = game.Workspace
    SummonedObject.Position = Vector3.new(ClickPosition.x, ClickPosition.y + SummonHeight, ClickPosition.z)

    local ObjectTweenInfo = TweenInfo.new(SummonTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    local ObjectTween = game:GetService("TweenService"):Create(SummonedObject, ObjectTweenInfo, {Position = ClickPosition})
    
    ObjectTween.Completed:Connect(function()
        warn("Tween Finished")
    end)
    
    ObjectTween:Play()
end)

Trying this out and still- absolutely nothing. Tool.Activated not working, could it be a roblox studio bug?

It might be the User’s Interface, have you tried this without the interface present?

How about this, this will give you an idea on if the script started and whether or not the activation process started.

local Tool = script.Parent
local ObjectToSummon = game.Workspace.ObjectToSummon
local SummonHeight = 20
local SummonTime = 1.5

Tool.Activated:Connect(function()
    print("Activated")
    local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
    if not Player then
        print("Player not found")
        return
    end

    local Mouse = Player:GetMouse()
    local ClickPosition = Mouse.Hit.p

    local SummonedObject = ObjectToSummon:Clone()
    SummonedObject.Parent = game.Workspace
    SummonedObject.Position = Vector3.new(ClickPosition.x, ClickPosition.y + SummonHeight, ClickPosition.z)

    local ObjectTweenInfo = TweenInfo.new(SummonTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    local ObjectTween = game:GetService("TweenService"):Create(SummonedObject, ObjectTweenInfo, {Position = ClickPosition})
    
    ObjectTween.Completed:Connect(function()
        warn("Tween completed")
    end)
    
    ObjectTween:Play()
end)

Well I was right, it was the GUI elements which does suck because I was really hoping to have that in my game. I guess I’ll have to find a different way to do this, like using a keybind instead of a click, thank you for helping!

Have you tried giving the Interface a high ZIndex therefore it’s above most of the workspace’s instances and the other GUI’s?

Gui.ZIndex = 10

Also ensure your Tool has the HandleRequired property set to false.