I have an alternative solution and I am testing something right now, depending on what happens, I’ll mark what I feel is most likely the best answer.
I made an code above, try using it.
Here Is A Tip On The Click Event make sure its the server script
and before you make the game pass prompt you should make sure that they do not own the gamepass this should be very easy to do
So I tried your code, and it seems to fix it with the card problem. Thank you for the solution, and I also marked it.
I’ll change the solution then, but thanks for the updated code!
Although you have already found a solution, I will show you a better and safer way to deal with it here, so exploiters will not be able to take advantage of your system. In this case I will use some replication services, see below:
--> ServerScriptService
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local CardEvent = ReplicatedStorage:FindFirstChild('CardEvent')
local Card1 = ServerStorage:FindFirstChild('CardLevel_1')
local Card2 = ServerStorage:FindFirstChild('CardLevel_2')
local GamepassID = 0
Players.PlayerAdded:Connect(function(Player)
--> Let's wait for the character to be added!
Player.CharacterAdded:Connect(function(Character)
--> Now we have a character, so let's check if the player have the gamepass.
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
local Clone = Card2:Clone()
Clone.Parent = Character
else
local Clone = Card1:Clone()
Clone.Parent = Character
end
end)
end)
workspace.Reader.Touched:Connect(function(Part)
if Part.Parent.Name == 'CardLevel_1' or Part.Parent.Name == 'CardLevel_2' then
--> Getting the player from his character
local Player = Players:GetPlayerFromCharacter(Part.Parent.Parent)
--> Double check!
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
CardEvent:FireClient(Player, true)
[TestPlace_Card.rbxl|attachment](upload://5CFDqVYHScMTZ8Xqgfc4hP6Zwck.rbxl) (21,0,KB)
else
--> If the player doesn't have the gamepass, let's give him a chance to buy!
CardEvent:FireClient(Player, false)
MarketPlaceService:PromptGamePassPurchase(Player, GamepassID)
end
end
end)
Now we have this Script, let’s create a LocalScript at StarterPlayer.StarterCharacterScripts
, which will only load when a Player have a Character;
--> StarterPlayer.StarterCharacterScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CardEvent = ReplicatedStorage:FindFirstChild('CardEvent')
local Door = workspace.Door
local Reader = workspace.Reader
--> Here this specific player will receive the event from server
CardEvent.OnClientEvent:Connect(function(Value)
if Value then
--> If the player have acces, them let's continue
Door.CanCollide = false
Door.Transparency = 1
Reader.Material = Enum.Material.Neon
Reader.BrickColor = BrickColor.Green()
wait(1)
Door.CanCollide = true
Door.Transparency = 0
Reader.Material = Enum.Material.SmoothPlastic
Reader.BrickColor = BrickColor.White()
else
--> If the doesn't have access, let's tell him!
Reader.Material = Enum.Material.Neon
Reader.BrickColor = BrickColor.Red()
wait(0.5)
Reader.Material = Enum.Material.SmoothPlastic
Reader.BrickColor = BrickColor.White()
end
end)
Warning
Note that at no time does the server receive events from the client, only the client receives events from the server. This is important to avoid exploits and false calls to the server, and that when using a LocalScript, we can cause certain actions to be replicated for only one player, and not all.
Take the place I used in this example!
TestPlace_Card.rbxl (21,0,KB)
I hope I’ve helped