Hi I’m new to scripting. I have tried a lot of things but still I can’t. If someone has a certain game pass it gives more energy to certain tools. But if someone has the game pass, the whole server gets more energy. And I want only the player who has the game pass to get more energy.
This is my script.
You should create a remote event, then fire the client if the player owns the game pass. On a local script, change these values and then it will only apply to that player.
Next, make a local script on the client. In this script put:
game.ReplicatedStorage.purchaseHandler.OnClientEvent:Connect(function()
-- put all of your configure changes in here
end)
Sorry if this isn’t the best help! You might have to make two different remotes or just pass an argument if you have more than one gamepass changing local configuration.
this is my new script:
error:
[ ServerScriptService.Script:9: attempt to perform arithmetic (add) on userdata and number]
game.Players.PlayerAdded:Connect(function(Player)
local Energy = Player:WaitForChild("leaderstats").Energy
local Id = 9002245
local multiple = 0
local n = 0
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(Player.UserId,Id) then
multiple = 2
Energy = Energy + n * multiple
end
end)
if mps:UserOwnsGamePassAsync(Player.UserId,9002245)
Well for checking if UserOwnsGamePassAsync you don’t need to add the player’s UserId as a parameter instead add the main player as the first parameter. So it should look like this
if mps:UserOwnsGamePassAsync(Player,9002245)
also use elseif instead of having multiple if statement at a single scope so you won’t have to put tons of ends. Your script should look like this
What? Only the player who has the pass? Bruh why did you put all the items in serverstorage if you want the change to only occur for the player who has the pass? Also if you didn’t know the whole server will receive the changes but not the players (Including the player who has the pass) because clients cannot access ServerStorage therefore you need to use RemoteEvents or RemoteFunctions to access ServerStorage by making a ServerScript pickup a request from the client.
But who has a fix for this.
error:
[ ServerScriptService.Script:9: attempt to perform arithmetic (add) on userdata and number]
game.Players.PlayerAdded:Connect(function(Player)
local Energy = Player:WaitForChild("leaderstats").Energy
local Id = 9002245
local multiple = 0
local n = 0
local mps = game:GetService("MarketplaceService")
if mps:UserOwnsGamePassAsync(Player.UserId,Id) then
multiple = 2
Energy = Energy + n * multiple
end
end)