Ad
Log in to vote
0

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

Asked by 2 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.

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

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

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

Answer this question



Ad