I’m working on a simulator, and basically, when you click a GUIButton, you get a click, which goes into leaderstats. I tried to edit the click script to allow me to incorporate a double clicks gamepass.
local button = script.Parent
local id = 28932538
game.Players.PlayerAdded:Connect(function(player)
local function onButtonActivated()
if game:GetService("GamePassService"):PlayerHasPass(player, id) then
print("Double Clicked!")
game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Clicks").Value += 2
else
print("Clicked!")
game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Clicks").Value += 1
end
end)
end
button.Activated:Connect(onButtonActivated)
I’m not sure what I did wrong, but a lot of stuff is underlined and clicking the button doesn’t work anymore. Any tips?
this should work, not sure why you had a playeradded in a local script,
add this script in the child of the button
also, make sure you have a remote event to the server including the player in the parameters to add the leaderstat value to the server so everyone can see it.
local button = script.Parent
local id = 28932538
local player = game.Players.LocalPlayer
local function onButtonActivated()
if game:GetService("GamePassService"):PlayerHasPass(player, id) then
print("Double Clicked!")
game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Clicks").Value += 2
else
print("Clicked!")
game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Clicks").Value += 1
end
end
button.Activated:Connect(onButtonActivated)
There was no outputs in studio, but I tested it in game (thats were gamepasses work) and it said:
Game passes can only be queried by a Script running on a ROBLOX game server
This is because the script is local. You would need to use remote events for this to be showable on all leaderboards for other people then the local player.
Doing this method could also make the system more secure.
local players = game:GetService('Players')
players.PlayerAdded:Connect(function(player)
if player then
local folder = Instance.new('Folder')
folder.Name = 'leaderstats'
folder.Parent = player
local clicks = Instance.new('IntValue')
clicks.Name = 'Clicks'
clicks.Parent = folder
clicks.Value = 0
local coins = Instance.new('IntValue')
coins.Name = 'Coins'
coins.Parent = folder
coins.Value = 50
end
end)
Funnily enough, I didn’t write the entire thing. Me and a friend hired someone to script some stuff, but he quit halfway through. I had to revamp all his stuff
Alright you need to insert a script into ServerScriptService and insert this code:
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("GamepassRemote")
local GamepassID = 28932538
local function Add(player)
print("Received Remote")
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
local Leaderstats = player:WaitForChild("leaderstats"):WaitForChild("Clicks")
Leaderstats.Value = Leaderstats.Value + 2
else
local Leaderstats = player:WaitForChild("leaderstats"):WaitForChild("Clicks")
Leaderstats.Value = Leaderstats.Value + 1
end
end
Remote.OnServerEvent:Connect(Add)
In the local script insert this code: (In the gui button)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("GamepassRemote")
script.Parent.MouseButton1Down:Connect(function()
print("Sent Remote")
Remote:FireServer()
end)
The benefits of checking if a user owns the gamepass on the server is the fact that its not exploitable as any local script a client would have access to but server scripts they don’t.