Hello there im having problems picking a random magic from a table using math.random. Youtube wont help me so i want to ask u guys for help.
function OnPlayerAdded(Player)
Player:WaitForDataReady()
Player = game.Players.LocalPlayer
Magic = Instance.new("StringValue", Player)
Magic.Name = "Magic"
if Player:LoadString("Magic") ~= "" then
Magic.Value = Player:LoadString("Magic")
else
Elements = {"Water", "Fire", "Earth"}
i = math.random(1, #Elements)
Player.Magic.Value = Elements[i]
Player:SaveString("Magic" , Player.Magic.Value)
M = Instance.new("Message", workspace)
M.Text = Magic.Value
game.Debris:AddItem(M, 5)
end
if Player.Magic.Value == "Fire" then
x = game.Lighting.Fireball:clone()
elseif Player.Magic.Value == "Water" then
x = game.Lighting.Waterball:clone()
elseif Player.Magic.Value == "Earth" then
x = game.Lighting.Rockball:clone()
end
x.Parent = Player.Backpack
end
game.Players.PlayerAdded:connect(OnPlayerAdded)

6 comments
Have you even attempted at making the script? And there is this thing called wiki.roblox.com I suggest looking on it.
Yes i ready have here it is:
If I remember correctly, WaitForDataReady was broken. If you take that out, your script should work.
Still wont work :(
Why are you changing Player to the LocalPlayer when you've already got the player? What type of script are you using?
A script normal one