local waittime = 60
local GamepassID = 10951455
script.Parent.Touched:Connect(function(hit)
local character --get the character from hit.Parent
local player --get player from character, i forget the api to get player from character
local hasGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player, GamepassID)
if not hasGamepass then
--code for if the player does not have gamepass
else
--code for if the player does have gamepass
end
end)
just follow the above(don’t copy and paste since I probably have syntax errors like the first time), and it should work out. p.s. I also tried not to give you a completed script and more of a outline so you can learn.
Yeah, right now it’s giving 1 coin, waiting 60 seconds, then giving the other 2. Like I said, you can move the gamepass code up if you don’t want that:
local waittime = 60
local GamepassID = 10951455
-- local Player = game.Players.LocalPlayer: get rid of this, it's server-sided so the LocalPlayer doesn't exist
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local pointsStore = DataStore2("MovieBux", player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, GamepassID) then
-- check for the player who touched, not the variable Player ("localplayer", aka nil)
pointsStore:Increment(2) -- Give them 2 point
print("Granted 2 Coins")
else
print("Granted 1 Coin")
pointsStore:Increment(1) -- Give them 1 point
end
script.Parent.Transparency = 1 -- no matter what, the same thing happens with transparency
script.Disabled = true -- disabling it won't do anything though by the way
wait(waittime)
script.Parent.Transparency = 0
script.Disabled = false
end
end)
If you want them to receive two if they have the gamepass, rather than 1 coin followed by 2 more, you can use an if-else similar to what Ocipa’s been doing. (I added that tweak to the code.) Just a couple other notes: Disabling a script won’t do anything, and the LocalPlayer is nil on the server. (@Ocipa, your code has been doing Player when the variable is player. That’s probably because you copied it, and it was checking if the “LocalPlayer” under the variable Player was the one who owned it rather than whoever touched the part.)
No you don’t. if value then will go through if value is anything but false or nil. Try if 1 then, it’ll pass the conditional. x == y just evaluates to true if they’re equal, and false if not. It has no special behavior in a conditional.