Hello, I’m new to scripting, and I’m just trying to make a small game. And what im trying to script in this game is a /sg spawner like them ones where you would say /sg glock or something and the glock is then in your inventory. This also needs to be a game pass. I have looked around and can’t find anything, so this is my last option.
research how to create custom chat commands
But how would i make that a gamepass only command
check if they own the gamepass before fivinf them the weapon
I put “I’m new to scripting” for a reason. (not trying to be rude btw)
so there is the marketplaceservice that lets you check if somebody has a gamepass
user owns gamepass async
https://create.roblox.com/docs/reference/engine/classes/MarketplaceService#UserOwnsGamePassAsync
There is a difference between “I’m new to scripting” and “Write a full code for me because you have nothing better to do”.
This is not a category to ask for full scripts, this is a category to ask for a little support about specific things.
(not trying to be rude btw)
local plrs = game.Players -- gets all the players within the server currently
local plr = game.Players.LocalPlayer -- gets the local player of this script
local chr -- a recursive variable (refreshes on spawn)
local userID = plr.UserId -- takes their userID
local gamepassID = 1234567890 -- let's say this is your gamepass' ID
plr.CharacterAdded:Connect(function(chr2) -- triggers when character loads/reloads in
chr = chr2 -- overrides chr with chr2 which is plr's current char
end)
local repSto = game:GetService("ReplicatedStorage") -- let's say your gun is stored in the replicated storage
local sampleItem = repSto:WaitForChild("Glock") -- e.g this is your gun as aforementioned, being referred to
local marketserv = game:GetService("MarketplaceService") -- main serv for "gamepasses" as you wanted
plr.Chatted:Connect(function(msg) -- fires when player chats
if marketserv:UserOwnsGamePassAsync(userID, gamepassID) then -- checks if they own the gamepass
local hum = chr:WaitForChild("Humanoid") -- look sfor a hum obj in the chr
if (hum ~= nil) and (hum.Health > 0) then -- ensures if they are not dead
if msg == "/sg glock" then -- ensures if it's the correct prompt
if not chr:FindFirstChild("Glock") or plr.Backpack:FindFirstChild("Glock") then -- ensures if they do not have the gun
local cloned = sampleItem:Clone() -- clones it, obviously
cloned.Parent = plr.Backpack -- hurray they got it now!
end
end
end
end
end)
i wrote some informational lines so you understand the processes of the script
I learn more effectively when something is in front of me. Being told stuff would not make much sense to me, so ideally, seeing things in front of me would help me learn better. Sorry for making you mad Dav_Jacobs
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.