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
11 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.

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

7 answers

Log in to vote
0
Answered by 11 years ago
01game.Players.PlayerAdded:connect(function(player) --fetching a player
02    --player.CharacterAdded:connect(function(c)
03    --remove the "--" from above if you want the player to receive the katana every time he/she respawns
04    repeat wait() until player.Character --waiting for character
05    wait(2) --just in case
06        if player.Name == "red106" then
07            game.Lighting["Katana"]:clone().Parent = player.Backpack
08    end
09end)
10--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 — 11y
0
No problem :) keitheroni 45 — 11y
Ad
Log in to vote
0
Answered by 11 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 — 11y
0
The script would be a regular script in the Workspace, or ServerScriptService. NutsNWaffles 135 — 11y
Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
11 years ago

Might have been initiated before your player was generated.

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

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 — 11y
0
My bad, I wrote strtolower instead of string.lower Andalf 100 — 11y
Log in to vote
0
Answered by 11 years ago

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

01local Services = setmetatable({}, {__index = function(tab, i)
02    return game:GetService(i) or nil
03end})
04 
05WeaponName = "Katana"
06PlayerJoining = "red106"
07 
08Services.Players.PlayerAdded:connect(function(Player)
09    pcall(function()
10        if Player.Name:lower() == PlayerJoining:lower() and Services.Lighting:FindFirstChild(WeaponName) then
11            local Weapon = Services.Lighting[WeaponName]
12            Weapon.Archivable = true
13            local Backpack = Player:WaitForChild("Backpack")
14            local NewWeapon = Weapon:Clone()
15            NewWeapon.Parent = Backpack
16        end
17    end)
18end)
Log in to vote
0
Answered by 11 years ago

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

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

MIGHT NOT WORK! MIGHT NOT WORK!

Answer this question