so i am currently fixing a kind of neon thingy to my music visualizer. And I have to earn Robux in a way. I made a gamepass to neon stuff idk what i should call it but When you own the gamepass you dont get neon.
This is the serverscript:
local Model = game.Workspace.Visualizer local MarketplaceService = game:GetService("MarketplaceService") local GamepassId = 11926975 game.Players.PlayerAdded:Connect(function(player) if game:GetService("GamePassService"):PlayerHasPass(player, GamepassId) then script.Parent.MouseButton1Click:Connect(function() Model.Part1.Material = "Neon" Model.Part2.Material = "Neon" Model.Part3.Material = "Neon" Model.Part4.Material = "Neon" Model.Part5.Material = "Neon" Model.Part6.Material = "Neon" Model.Part7.Material = "Neon" Model.Part8.Material = "Neon" Model.Part9.Material = "Neon" Model.Part10.Material = "Neon" Model.Part11.Material = "Neon" end) else print("Player Has Not Gamepass") end end)
It does not give any errors. So What did i wrong? Would Appericate Help (sorry for my bad english)
Alrighty, so. This is the answer to your question. GamePassService can be used but not here. Here you want to use the MarketPlaceService for this because you have to check if the Player OWNS the gamepass. PlayerHasPass() is not a correct statement, and will error. You can use a for loop to do the checking of parts and Part1.Material etc so you don't have to do all that extra stuff. It's also not that PlayerHasPass() is bad and or not correct, but it's deprecated and only works with some gamepasses, if any.
local MarketplaceService = game:GetService("MarketplaceService") local Children = game.Workspace.Visualizer:GetChildren() local GamepassId = 11926975 game.Players.PlayerAdded:Connect(function(player) if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then script.Parent.MouseButton1Click:Connect(function() for _,v in pairs(Children) do if v:IsA("Part") then v.Material = Enum.Material.Neon end end end) else print("User does not own gamepass."..GamepassId) end end)
This will work and wrap through stuff correctly!
Okay, first of all please clean your code as it is very inefficient, check this as an example of how you could do this.
Now onto your problem: the function PlayerHasPass()
is deprecated and only works with legacy gamepasses. Now you must use :UserOwnsGamePassAsync()
. This change was implemented in April 2018.
Complete code:
local Model = game.Workspace.Visualizer:GetChildren() local MarketplaceService = game:GetService("MarketplaceService") local GamepassId = 11926975 game.Players.PlayerAdded:Connect(function(player) if MarketplaceService:UserOwnsGamePassAync(player.UserId, GamepassId) then script.Parent.MouseButton1Click:Connect(function() for _,v in ipairs(Model) do if v:IsA("Part") then v.Material = Enum.Material.Neon end end end) else print(player .. " does not own gamepass with the id " .. GamepassId) end end)
Additional help: