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

Can someone please help me? [Explanation in description]

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.

Hello I am new to Lua and I know very little now with this script, what I am trying to do is make a script that randomizes each players weapon, for example lets say theres 4 players in my game, then each one of them will recieve a different weapon that was stored in lighting, heres the script, also when I try playing solo my character won´t appear in that place.

game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) repeat wait() until p:FindFirstChild("Backpack") game.Lighting:GetChildren()[math.random(1, #game.Lighting:GetChildren())]:clone().Parent = p.Backpack end) wait(2) end)

3 answers

Log in to vote
0
Answered by
Mowblow 117
10 years ago

Roblox does has some glitches and stuff like this happens to me a lot! Try putting the code in a new place (I don't see anything wrong with the code) and run it. If this does not work, I am baffled.

Ad
Log in to vote
0
Answered by 10 years ago

Here, try this. Put all the weapons in ServerStorage, it's the best place to put them.

game.Players.PlayerAdded:connect(function(p)
    local tools = {game.ServerStorage.tool1:Clone(), game.ServerStorage.tool2:Clone(),  game.ServerStorage.tool3:Clone(), game.ServerStorage.tool4:Clone()}
    local randTool = tools[math.random(#tools)]
    if p:FindFirstChild("BackPack") then --backpack isnt part of character it's in the player
        randTool.Parent = p.BackPack
    end
end)

That should work! Comment if it didn't.

0
Sorry I can´t test it because of my freaking glitched studio it says "Waiting for character" when I try playing in my place biocommand 30 — 10y
Log in to vote
0
Answered by 10 years ago

The player added event does not fire in solo mode because the player is created before any scripts with playeradded run. If you really want to test this in solo mode add this to the end of your script.

for _, player in pairs(game.Players:GetPlayers()) do
    PlayerAdded(player) -- Use your player added handling function here.
end

Alternatively you can start a local server (f7) and then start players (alt + f7).

Answer this question