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)
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)
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.