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

Trying to give myself a needle gun when i join my game Can anybody help me?

Asked by 4 years ago

This is the code, i works on studio but not in game, I DO have API on

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "Pipe_Gamerz" then
         local Potato = game.ReplicatedStorage.Needlegun:Clone()
        Potato.Parent = game.Players.Pipe_Gamerz.Backpack
        local Potato2 = game.ReplicatedStorage.Needlegun:Clone()
        Potato2.Parent = game.Players.Pipe_Gamerz.StarterGear
    end
end)

Help is extremely appreciated

0
remove the Local from your variables if3q 6 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

So It seems a lot of people have problems using Players, so Im guessing that is is deprecated. use this instead:

local function giveTool(player, tool) -- easier and removes the chance for failure
    local backpack = player:FindFirstChildOfClass("Backpack")
    if backpack then
        tool.Parent = backpack
    end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
    if plr.Name == "Pipe_Gamerz" then
    print("Test")
         local Potato = game.ReplicatedStorage.Needlegun:Clone()
    giveTool("Pipe_Gamerz", Potato)
        local Potato2 = game.ReplicatedStorage.Needlegun:Clone()
    giveTool("Pipe_Gamerz", Potato2)
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

This will probably work

local target = "Pipe_Gamerz" -- name
game.Players.PlayerAdded:Connect(function(plr)) -- check if a player joined
    if plr.Name == target then -- if the player joined's name is target's name then
        print(target.." Found in the server. giving "..target.." the tool.") -- print that we found the player you can remove it
        local toolClone = game.ReplicatedStorage.MyTool:Clone() -- make a clone so whenever you join the server again it gives you the tool again
        toolClone.Parent = plr.Character -- for making him hold it instantly
        -- toolClone.Parent = plr.Backpack -- for adding it to his inventory without holding it
    else -- if the player name isn't the target's name then
        print("Target was not "..target.." skipping.") -- print that the player was not the player we are looking for
    end -- ends 'if plr.Name == target then'
end) -- ends 'game.Players.PlayerAdded:Connect(function(plr))'

Answer this question