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

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

Asked by 6 years 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.

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

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years 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
0
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 — 6y
0
Do you want the player click twice before the movement happens? ZeExplosion 210 — 6y
0
This helps a lot, thanks for the extra code. Now I can finally start working on other parts of the game. Explosivesguy2 20 — 6y
Ad

Answer this question