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

My script won't work, can someone help me?

Asked by
red106 0
10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I was trying to make a script that when a certain person enters that it would equip them with a certain weapon and yes I put the weapon in Lighting, but for some reason it won't work.

Game.Players.PlayerAdded:connect(function(player)
    wait()
    if player.Name == "red106" then
        Game.Lighting["Katana"]:clone().Parent = player.Backpack
    end
end)

7 answers

Log in to vote
0
Answered by 10 years ago
game.Players.PlayerAdded:connect(function(player) --fetching a player
    --player.CharacterAdded:connect(function(c)
    --remove the "--" from above if you want the player to receive the katana every time he/she respawns
    repeat wait() until player.Character --waiting for character
    wait(2) --just in case
        if player.Name == "red106" then
            game.Lighting["Katana"]:clone().Parent = player.Backpack
    end
end)
--end) --if you deleted the "--" from line 2, then remove the "--" here

Above should work.

0
THANK YOU! This is the only one that worked. red106 0 — 10y
0
No problem :) keitheroni 45 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

This should work just fine. The only reason it wouldn't work is if you are doing this on Solo Test. Either way, use the "print()" command to see if it goes through both conditions.

0
Would I put the script in my workspace and would it be a regular script or local? red106 0 — 10y
0
The script would be a regular script in the Workspace, or ServerScriptService. NutsNWaffles 135 — 10y
Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

Might have been initiated before your player was generated.

Game.Players.PlayerAdded:connect(function(player)
repeat wait() until Workspace:findFirstChild(player.Name)
if (player.Name == "red106") then
Game.Lighting["Katana"]:clone().Parent = player.Backpack
end
end)
Log in to vote
0
Answered by
Andalf 100
10 years ago
game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        if string.lower(char.Name) == "red106" then
            game.Lighting["Katana"]:clone().Parent = char.Backpack
        end
    end)
end)

This will add the katana to the characters backpack rather than the players, but it will happen every time the character is created.

Add this as a regular script in the workspace, also use game not Game.

0
I don't know why but the script won't work. red106 0 — 10y
0
My bad, I wrote strtolower instead of string.lower Andalf 100 — 10y
Log in to vote
0
Answered by 10 years ago

I improved all previous answers and the original code to make it as secure as possible:

local Services = setmetatable({}, {__index = function(tab, i)
    return game:GetService(i) or nil
end})

WeaponName = "Katana"
PlayerJoining = "red106"

Services.Players.PlayerAdded:connect(function(Player)
    pcall(function()
        if Player.Name:lower() == PlayerJoining:lower() and Services.Lighting:FindFirstChild(WeaponName) then
            local Weapon = Services.Lighting[WeaponName]
            Weapon.Archivable = true
            local Backpack = Player:WaitForChild("Backpack")
            local NewWeapon = Weapon:Clone()
            NewWeapon.Parent = Backpack
        end
    end)
end)

Log in to vote
0
Answered by 10 years ago

So where should this script be in? Workspace, Lightning?

Log in to vote
0
Answered by 10 years ago
game.Players.PlrAdded:connect(function(plr)
wait(1)
if newPlr.Name == "red106" then
game.Lighting.["Katana"]:clone().Parent = plr.Backpack
local kd = "red106"
if kd =="red106" then 
Katana:clone() -- Incase you dropped it
end
end
end)

MIGHT NOT WORK! MIGHT NOT WORK!

Answer this question