Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a gamepass to give a sword when hit a part?

code is this


local id = 7746555
local MarketPlaceService = game:WaitForChild:FindFirstChild("MarketplaceService") 
local Players = game:("Players")
local Sword = game.ServerStorage.Sword
local debounce = true

local part = script.Parent
local function onTouched(part)  
    local player = Players:GetPlayerFromChar(part.Parent.)
    if not player then return end
        if debounce == true then
            if MarketPlaceService:UserOwnerOfGamePass(UserId id) then
            local backpack = player.Backpack
            debounce = false
            Sword:Clone(1).Parent = backpack
            wait (1)
            debounce = true
        end
    end
end
part.Touched:Connect(onTouched) == true

1 answer

✓ Accepted answer

Old script:


local id = 7746555
local MarketPlaceService = game:WaitForChild:FindFirstChild("MarketplaceService")  -- This is incorrect, It’s suppose to be game:GetService("MarketplaceService"). also, never use findfirstchild after wait for child
local Players = game:("Players")
local Sword = game.ServerStorage.Sword
local debounce = true

local part = script.Parent
local function onTouched(part)  
    local player = Players:GetPlayerFromChar(part.Parent.) -- it’s suppose to be GetPlayerFromCharacter
    if not player then return end
        if debounce == true then
            if MarketPlaceService:UserOwnerOfGamePass(UserId id) then -- There are like 4 errors in this, you need assistance with questions
            local backpack = player.Backpack
            debounce = false
            Sword:Clone(1).Parent = backpack
            wait (1)
            debounce = true
        end
    end
end
part.Touched:Connect(onTouched) == true -- Don’t add == true

New script:


local id = 7746555
local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Sword = game.ServerStorage.Sword
local debounce = true

local part = script.Parent
local function onTouched(part)  
    local player = Players:GetPlayerFromCharacter(part.Parent.)
    if not player then return end
        if debounce == true then
            if MarketPlaceService:UserOwnsGamePassAsync(player,UserId id) then
            local backpack = player.Backpack
            debounce = false
            Sword:Clone(1).Parent = backpack
            wait (1)
            debounce = true
        end
    end
end
part.Touched:Connect(onTouched)

You have numerous errors, I recommend researching this topic.

2 comments

0

Doesn’t work

0

Nevermind

This discussion is preserved as it was. New answers, comments, and votes are closed.