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

how would i use a then statement when the mouse is down?

Asked by 5 years ago
Edited 5 years ago

So I'm trying to make an anti cheat so i would do

  game.ReplicatedStorage.Money.OnClientEvent:Connect(function(1)
        if Mouse1Down then
            Player.leaderstats.Money.Value +1
        end
    end)

1 answer

Log in to vote
0
Answered by 5 years ago

First of all, I can see you're using a remote event. You have it set up right, but this line: game.ReplicatedStorage.Money.OnClientEvent:Connect(function(1) has a problem. Client Event events aren't able to pass raw numbers (in this case, 1), so that's one thing. Deleting the 1 would be a good start. Then, if you want to detect mouse input, you have to use the Button1Down event, which would look like this:

local Mouse = game.Players.LocalPlayer:GetMouse() --- get the mouse via local player.
game.ReplicatedStorage.Money.OnClientEvent:Connect(function()
        Mouse.Button1Down:Connect(function()
            Player.leaderstats.Money.Value +1
            end)
        end
      end)

That's better. Now, another thing is math. You cannot do Player.leaderstats.Money.Value +1, and what you do instead is Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1. Another thing to keep in mind is that RemoteEvents pass down Player as a variable, so the complete script would work and look like this, assuming "leaderstats" are a thing in Player and "Money" is a number value under leaderstats:

local Mouse = game.Players.LocalPlayer:GetMouse() --- get the mouse via local player.
game.ReplicatedStorage.Money.OnClientEvent:Connect(function(Player) --- Pass over Player.
          Mouse.Button1Down:Connect(function()
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
          end)
      end
 end)

Alternatively, this can be done:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse() --- get the mouse via local player.
game.ReplicatedStorage.Money.OnClientEvent:Connect(function() --- No need to pass over player, cause it's defined as the same thing already.
    Mouse.Button1Down:Connect(function()
        Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
        end)
    end
end)

I hope this cleared up the question for you. If you found this useful, mark this answer as the solution.

Ad

Answer this question