Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this script work?

This is suppose to give plays on spawn random weapon can you please tell me whats wrong with it?

player = part.Parent:findFirstChild("Humanoid")


function onPlayerEntered(player)
	
local Item = game.Lighting:FindFirstChild(math.random)

Item:clone().Parent = player.Backpack
	wait(2)

print 'Working'

end




game.Players.PlayerAdded:connect(onPlayerEntered)
onPlayerEntered(game.Players:WaitForChild("Player1"))

2 answers

✓ Accepted answer

Judging by your attempt, the items are in game.Lighting. So if its not please PUT EM THERE. Use this. It will put it in their backpack NOT their startergear so if they die they dont obtain it again but if you want them to just keep spawning random items when they spawn reply with a yes and ill come up with a quick script :D

function GiveWeap(des)
	local items = game.Lighting:GetChildren()
	items[math.random(1,#items)]:Clone().Parent = des.Backpack
end

game.Players.PlayerAdded:connect(function(plr)
	plr:WaitForChild("Backpack")
	GiveWeap(plr)
end)

1 comment

0

So i guess yes id like them to receive the same item even though they died

At the top 'findFirstChild' is supposed to be FindFirstChild. You also have two player variables. You may need to change one of the variables to something else. 'Item:clone()' should be Item:Clone(). Other than that I don't know, sorry.

2 comments

0

Thank you but there is still something that make it wrong or something needed to make it work

0

Actually. FindFirstChild and findFirstChild are correct.

This discussion is preserved as it was. New answers, comments, and votes are closed.