Plant growing scirpt not working?

Well since the input began fires on walking aswell, it spams. Also, when I press F again, it does not fire anything new and says “Seed is not a vlaid member of model” meaning it trys only the first.

What line is the error occurring on?

I figured out the problem with the error. I just dont want this spamming the output when I walk, etc.

Wrap everything in the event in an if statement that checks if the key code is equal to F. That way, any key except F will not make anything happen. If you want, you can then remove the check on the if statement you have now for the key code. That should stop the message when any key other than F is pressed.

Your code may look like this:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()
local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(inst)
    if inst.KeyCode == Enum.KeyCode.F then
	    print("began input")
        if mouse.Target and inst.KeyCode == Enum.KeyCode.F and mouse.Target.Finished.Value == false and mouse.Target.Name == 'PlantDetector' and mouse.Target.Parent.Name == 'Plant1' and Player.Character.Seed and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 then
	        print("Finished")
	        local Plant = mouse.Target
            game.ReplicatedStorage.GrowPlant:FireServer(Plant)-- stop code if it isnt false
            print("Fired")
        else
	        print("began input (to get stuff)")
            if mouse.Target and inst.KeyCode == Enum.KeyCode.F and mouse.Target.Finished.Value == true and mouse.Target.Name == 'PlantDetector' and mouse.Target.Parent.Name == 'Plant1' and Player.Character.Seed and (Player.Character.HumanoidRootPart.Position - mouse.Hit.p).magnitude <= 10 then
	            print("Finished")
                game.ReplicatedStorage.GivePlant:FireServer()
                print("Fired")
            end
        end
    end
end)

As you can see, we now check what key is pressed before doing anything, so no other key will trigger action. Hopefully, that will solve your problem.

This isn’t the most efficient way of doing things, but it should be ok for you.

If you have found the solution you are looking for, please mark a solution so more people don’t come to the thread.

1 Like