This script is supposed to create a function that checks if a string value is in your player, if it is not, it will randomly select an element from my table and give the player an "element" string. When i run this, i do not get an output nor do i get any errors. Also my print lines do not print. So i decided to mess around with the connection line and realized that my problem is calling the function. When i run the script with a wrong connection line(on purpose of course) then it will output the error, so i know that everything is right except my connection line? Any help is appreciated! Also, this script is inside a regular script(not local) and is placed into the workspace.
function onPlayerAdded(Player) Player:WaitForDataReady() Class = Instance.new("StringValue") Class.Parent = Player Class.Name = "Class" if Player:LoadString("Class") ~= "" then Class.Value = Player:LoadString("Class") print("Loading Succesful") else Elements = {"Fire", "Water", "Earth", "Wind","Lightning","Light"} i = math.random(1, #Elements) Player.Class.Value = Elements[i] Player:SaveString("Class",Player.Class.Value) print("Element was given") --Add Gui Displaying What Your Element Is. For now, just use message Message = Instance.new("Message") Message.Parent = Workspace Message.Text = Class.Text print("Message was Displayed") game.Debris:AddItem(Message, 7) end if Player.Class.Value == "Fire" then --do stuff here --x = game.Lighting.NAMEOFLOCALSCRIPT:clone() print("You have recieved the fire class") end if Player.Class.Value == "Water" then print("You have received the water class") --do stuff here end if Player.Class.Value == "Earth" then print("You have received the water class") --do stuff here end if Player.Class.Value == "Wind" then print("You have recieved the water class") --do stuff here end if Player.Class.Value == "Lightning" then print("You have recieved the lightning class") --do stuff here end if Player.Class.Value == "Light" then print("You have recieved the light class") --do stuff here end --x.Parent = Player.Backpack end game.Players.PlayerAdded:connect(onPlayerAdded)
Did you read the wiki? DataPersistance WORKS ONLY on game servers, so on the actual roblox website, not on local servers.
I suggest you to comment your DataPersistance loadstrings and see if the code works, then you can put them on code again.