Log in to vote

Click Detector Problems? (Need to try and grab the mouse and wait to click again)

Asked by 11 months ago

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.

    print ("Clicked")
    LSV = SeedSlot2.SunValue.Value
    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

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 :)

1 answer

Log in to vote
Answered by 11 months ago
Edited 11 months ago

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
Thank's, but there's still something i'm trying to solve. I need the script to wait for the player to click again after pressing the click detector somewhere on the ground before the script can continue to move the model. Is there a way to wait until the player clicks again? Explosivesguy2 20 — 11mo
Do you want the player click twice before the movement happens? ZeExplosion 205 — 11mo
This helps a lot, thanks for the extra code. Now I can finally start working on other parts of the game. Explosivesguy2 20 — 11mo

Answer this question