So I am trying to make an auto clicker game pass in my game but I have run into a problem with the system I am using. That is I am using a remote event to contact the server and update the leaderstats
my local script for the button -
local amount = 1
local timevalue = 0.5
local boolValue = script.Parent.StopButtonPressed
local player = game.Players.LocalPlayer
local rem = game.ReplicatedStorage.AutoclcikerAdder
local gamepassId = 22468201
local mp = game:GetService("MarketplaceService")
script.Parent.Parent.AutoclcikerOFF.MouseButton1Click:Connect(function()
boolValue.Value = true
script.Parent.Visible = true
script.Parent.Parent.AutoclcikerOFF.Visible = false
end)
if mp:UserOwnsGamePassAsync(player.UserId,gamepassId) then
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Visible = false
script.Parent.Parent.AutoclcikerOFF.Visible = true
boolValue.Value = false
repeat wait(timevalue)
rem:FireServer("true")
until boolValue == true
end)
else
mp:PromptGamePassPurchase(player,gamepassId)
end
My server code receiving the onserverevent -
local rem = game.ReplicatedStorage.AutoclcikerAdder
if game.StarterGui.Guis.AutoclickerOn.StopButtonPressed.Value == false then
rem.OnServerEvent:Connect(function(player)
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1
end)
else
print("Stopped")
end
So when the other button is pressed it isnt stopping it
in this block of code you list it as game.StarterGui.Guis.AutoclickerOn.StopButtonPressed
however, the player will modify player.PlayerGui.Guis.AutoclickerOn.StopButtonPressed
as all instances in starter gui get cloned to playergui
local rem = game.ReplicatedStorage.AutoclcikerAdder
if Player.PlayerGui.Guis.AutoclickerOn.StopButtonPressed.Value == false then --// Your job to find out how to get the player.
rem.OnServerEvent:Connect(function(player)
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1
end)
else
print("Stopped")
end
Hi, so personally, the best and easiest way to get the player from a server script is via any form of a function operating off of the player joining or an event ie; .Touched or RemoteEvent. As you’re using a remote event, I’d simply do it this way;
--// Server Script \\--
local rem = game.ReplicatedStorage.AutoclickerAdder
rem.OnServerEvent:Connect(function(player)
if player.PlayerGui.Guis.AutoclickerOn.StopButtonPressed.Value == false then
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1
else
print("Stopped")
end
end)
As this method finds you the player immediatly in the function parameters, and allows you to use it throughout your code. As it’s something operating with gui and only on the player who clicked the button, using player.PlayerGui is the best method to achieve this as the StarterGui would replicate for all players after spawn(s).
If this fails to function for you, best way to reach me is via discord @ BryanFehr#3070
There I can provide you with a further explanation and or examples or how I’ve achieved similar things in the past!
Thats not what im saying.
Auto clicker = fast right?
If you keep spamming the click then a memory leak is 100%
[Memory leak = your game is unplayable cause of the lag]