Recently I'm trying to make something akin to a remake of plants vs zombies on Roblox, but I ran into a problem. I'm trying to make it so when a player clicks on a "seed slot," it will get the players mouse and wait for it to click again somewhere so that it moves the model.
SeedSlot2.ClickDetector.MouseClick:Connect(function(player) print ("Clicked") LSV = SeedSlot2.SunValue.Value lowerSun() local newP = game.ServerStorage.Peashooter:Clone() newP.Parent = game.Workspace print ("Player who clicked is.. " ..player.Name) local mouse = player:GetMouse() local target = mouse.Hit.Position newP:MoveTo(Vector3.new(target)) end)
Ignore the "LSV" and "lowersun," that has nothing to do with it. Right now all it does is clone the plant model from the server storage but leaves it at it's original position without moving it; if I keep pressing the seed slot it will just keep making towers of plants. It also gives the error "Position is not a valid member of CFrame" for line 9. It would be nice if you could say what you use instead of Position.
Please reply as soon as you can, i'd really appreciate it :)
The mouse target is a CFrame, and therefore uses .p
over .Position
. Should be the only problem. If anything else arises, let me know.
Edit: It seems you want two clicks to make it work.
Add a variable, like local clicks = 2
prior to your function. Then, in the function, set it out like
if clicks == 2 then clicks = 1 -- seed slot code elseif clicks = 1 then clicks = 2 -- cloning code