Title says all, any help would be greatly appreciated!
(Script was not written by me)
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassId = 55244710
local Tool = script.GravityCoil
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
end)
This does check for the gamespass every time you respawn. Also, what I usually do is check if they have the gamepass right after they buy, if they do give the special thingy, that way all they have to do is buy it and nothing else.
I’ve tested with this script ingame and it only works after rejoining because of this part here but I’m not sure how exactly to fix it. It’s a problem because people have to rejoin the game after buying a pass in order for it to work.
The event CharacterAdded only gets called when the player joins, and I think this might be the issue.
I have an idea that uses RemoteEvents, but I assume you dont want to use it, since they are exploitable.
Let me know if you want to use only the server script, or by 2 scripts(LocalScript → RemoteEvent → server script)
I’m saying that the line Player.CharacterAdded:Connect(function(Character) comes right after game.Players.PlayerAdded:Connect(function(Player), which checks for a player getting added; i meant that it only checks once(only when the player gets added), not everytime a player respawns
function Spawned(player)
-- your code here
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
Spawned(player)
end)
end)
And you may want to add one more right after they buy it in game …
-- client side code, can be in StarterGui or smth
local RE = game:GetService("ReplicatedStorage").RemoteEvent -- going with the remoteevent way
local gamepass = -- gamepass here
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
RE:FireServer(gamepass)
end)
-- serverside code
local MarketPlaceService = game:GetService("MarketplaceService")
game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(player, gamepass)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, gamepass) then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
Add a function called CharacterAdded outside of PlayerAdded (or in a local function). Then, call it after 2.5 seconds after the player joins. Connect it up to CharacterAdded then you’re done.