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

Why doesn't this script work?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
game.Players.PlayerAdded:connect(function(player)
    if player.name == "tkdrocks2017" then
        print("GotThru")
        game.Lighting.Test:Clone().Parent = player.Backpack
    end
end)

My name is tkdrocks2017 and the name of the gear I am cloning is called Test, as stated in lines 2 and 4.

The purpose is to clone a tool from lighting and place it in the player's backpack.

Also, should I make this a localscript or a script?

0
Is your script not working, or are you just wondering whether it should be a LocalScript or a Script? To answer that, it should be a server-side script. Thewsomeguy 448 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

I don't suggest using Lighting as a storage anymore, now that we have ReplicatedStorage. Also, you should put this in a server-side script.

Edit: Try capitalizing .Name

0
What would that do and how would I fix the script? CardboardRocks 215 — 10y
0
Tell us the problem then? Output? Syntax Errors? This is merely a suggestion. PiggyJingles 358 — 10y
0
I'm not sure what the problem is. Sorry I can't help with that part. CardboardRocks 215 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Don't you need to fix the part where it says TEST and make it so it knows it's a new instance? This is the game pass one by ROBLOX, Maybe it would be possible to edit that and use it instead? Just a suggestion

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = Game:GetService('GamePassService')
local PlayersService = Game:GetService('Players')
local InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
    for _, tool in pairs(AdminTools:GetChildren()) do
        local toolClone = tool:Clone()
        toolClone.Parent = target
    end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
    if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
        local starterGear = WaitForChild(player, 'StarterGear')
        CloneAdminTools(starterGear)
        if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
            local backpack = WaitForChild(player, 'Backpack')
            CloneAdminTools(backpack)
        end
    end
end

--------------------
--| Script Logic |--
--------------------

-- Create AdminTools if it doesn't exist
if not AdminTools then
    AdminTools = Instance.new('Model')
    AdminTools.Name = 'AdminTools'

    -- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
    for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
        if intObject and intObject:IsA('IntValue') and intObject.Value then
            local assetModel = InsertService:LoadAsset(intObject.Value)
            if assetModel then
                local asset = assetModel:GetChildren()[1]
                if asset then
                    asset.Parent = AdminTools
                end
            end
        end
    end

    AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)

Log in to vote
0
Answered by
jmt99 35
10 years ago

Capitalize ".name" so it is ".Name"

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "tkdrocks2017" then
        print("GotThru")
        game.Lighting.Test:Clone().Parent = player.Backpack
    end
end)

Answer this question