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

Cannot get tool.Activated to create a specific part. Any Solutions??

Asked by 2 years ago

Hello everyone,

I'm working on a farming game right now, you might've seen my previous two posts the past several days, but i came across another issue that I have ABSOLUTELY NO IDEA how to fix. I made a tool called Seeds that when equipped, spawns a highlighter part on the ground and follows the players mouse at all times, and is supposed to instantiate some plants when you click with the tool equipped and the plant spawns where the highlighter is positioned.

Somehow I could not get this to work as the Seeds.Activated function just doesnt fire at all weirdly even with no errors being made and the tool being equipped. It might just be yet another classic case of incorrect referencing as im greatly prone to doing so I ask you guys yet again to please come and offer your assistence.

Any theories and suggestions are GREATLY appreciated!!

NOTE: I reduced the Activation function to its bare bones with only a print statement to guarantee if its working or not. It aint even with this solution.

CODE:

local Player = game.Players.LocalPlayer
local userinputService = game:GetService("UserInputService")
local Seeds = script.Parent
local mouse = Player:GetMouse()



Seeds.Equipped:Connect(function(player)
    if mouse.Target == game.Workspace.Baseplate then
        local Highlighter = game.ReplicatedStorage.Highlighter:Clone()
        Highlighter.Anchored = true
        Highlighter.Transparency = 0.5
        Highlighter.Material = "Neon"   
        Highlighter.CanCollide = false
        Highlighter.Parent = game.Workspace

        while true do
            local pos = mouse.Hit.Position
            Highlighter.Position = pos + Vector3.new(0, 0.5, 0)
            wait()
            mouse.TargetFilter = Highlighter
        end
    end 
end)

Seeds.Unequipped:Connect(function()
    local world = game.Workspace
    if world:FindFirstChild("Highlighter") then
        local Highlighter = game.Workspace.Highlighter
        Highlighter:Destroy()
        Highlighter.CanQuery = true
    end
end)

Seeds.Activated:Connect(function() --- Seeds.Activated does not fire upon clicking with the highlighter within mouse position.
    print("working!")
end)

Thanks!

0
Doesn't seem to be anything wrong with this script, I tested it in studio and it works fine for me. xInfinityBear 1777 — 2y

1 answer

Log in to vote
0
Answered by
ultrabug 306 Moderation Voter
2 years ago

This one was kind of a weird one to figure out. I think your problem is that the tool you give the player has the property "RequiresHandle" set to true, but the tool has no part named "Handle" so it can't be activated. So, you can either uncheck that, or add a part named "Handle" into the tool for the player to hold when they equip the tool.

0
The tool does have a handle. I just didn't reference it within the script as it wasn't really needed. Perhaps that might be the issue? Astrosupernuat 29 — 2y
0
I did test that out and it still shows no improvement. The original script SHOULD work as intended but as soon as i click on a random spot on the ground, it doesn't execute the code withn Seeds.Activated. Astrosupernuat 29 — 2y
0
Wild, I didn't have to reference the handle at all to get it to run on my end, it just had to exist under the tool. I'll try to look into this more later tonight. It is a localscript, right? ultrabug 306 — 2y
Ad

Answer this question