Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Im making a Gampass that gives you a weapon but it only in Roblox Studio, howcome?

Asked by 3 years ago
Edited by Ziffixture 3 years ago

I have a script where it gives you a Grenade launcher if you buy a gamepass, The problem is, It only works in Roblox Studio not in the real game. The script is located in Workspace cuz that's the only place it works in for some reason

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    print("PlayerAdded")
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 13440876) then
        local Replicated = ReplicatedStorage["Grenade Launcher"]:Clone()
        Replicated.Parent = Player:WaitForChild("Backpack")
        print("Gave Player Grenade Launcher")
        print(Player.Name)
    end
end)

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The issue with your script, is that you are cloning the tool only to the Backpack. Before I answer your question, next time you ask a question here, please make sure to be more descriptive with your questions, and, use code blocks to show your code. You can do that by pressing the Lua Icon above the description box and paste your code between the 2 lines of ~.

So, with your code, I was unsure what script you had, or where you had it, so, I have got a serverscript in ServerScriptService. This way, we also have access to ServerStorage, which is a very good way to store Tools and prevent exploits from getting them. What I have done with your script is that I changed the paths from ReplicatedStorage to ServerStorage, and also added the tool to StarterGear. This makes sure that even if you die, you will respawn with it!

local ServerStorage = game:GetService("ServerStorage") 
local Players = game:GetService("Players")

local MarketPlaceService = game:GetService("MarketplaceService")

Players.PlayerAdded:Connect(function(Player) 
    if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 13440876) then 
        local Tool = ServerStorage["Grenade Launcher"]:Clone()
        Tool.Parent = Player.Backpack
        Tool.Parent = Player.StarterGear
        print("Gave the item to "..Player.Name)
    end 
end)

Keep in Mind: This issue may also be caused by the fact that your place is not published! Please make sure your place is up to date with your updates and make sure everything is published.

I hope this helped you, and if it has, then feel free to Accept the answer, this gives both of us reputation!

Ad
Log in to vote
0
Answered by 3 years ago

first, what script is it a local or server script? if it is a server script then put it in ServerScriptService, also if you have Team Create enabled then check if collabrating editing is on, if yes then you have to commit the changes to the script and publish the game

0
and tell me if you get any errors, you can open the console in game by pressing F9 dionsyran2 66 — 3y
0
it is a server script, but whenever i move it to ServerScriptService the script doesnt even work. Team create is off KoalaTech 6 — 3y
0
I went inside the game and i wasnt getting any error message, It was printing saying that it gave me the Weapon too KoalaTech 6 — 3y
Log in to vote
0
Answered by
Gogulsky 129
3 years ago

How about you try this script? (works in Workspace) - you gotta put the grenade launcher inside of the ServerStorage. "PeopleWithFreeGamepass" are the ones that don't have to pay for the grenade launcher :)

local Id = 0
local PeopleWithFreeGamepass = {"person"}
local ToolName = {"Tool Here"}

local function FindPlayer(Plr)
    for Num, Pler in pairs(PeopleWithFreeGamepass) do
        if Pler == Plr then
            return true
        end
    end
end

game.Players.PlayerAdded:connect(function(Player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) or FindPlayer(Player.Name) then 
        Player.CharacterAdded:Connect(function(character)
            for Num, Tool in pairs(ToolName) do
                if game:GetService("ServerStorage"):FindFirstChild(Tool) then
                    game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
                end
            end
        end)

        for Num, Tool in pairs(ToolName) do
            if Player.Backpack:FindFirstChild(Tool) == nil then
                if game:GetService("ServerStorage"):FindFirstChild(Tool) then
                    game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
                end
            end
        end
    end
end)

Answer this question