after someone helped me with my other script in my simulator game, i tried making a "Delete Your Data" button. But now on line 4, its saying attempt to index local 'player' (a nil value)
can someone help me?
local delete = game:GetService("ServerStorage") script.Parent.MouseButton1Click:Connect(function(player) delete:FindFirstChild(player.UserId).Parent = workspace wait(1) delete:FindFirstChild(player.UserId).Parent = delete script.Parent.Parent.TextLabel.Text = "Deleted" wait(1.5) script.Parent.Parent.Visible = false script.Parent.Parent.TextLabel.Text = "Are You Sure? This Will Delete All Your Data." end)
my stats script:
local serverStorage = game:GetService("ServerStorage") local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3") game:GetService("Players").PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local strength = Instance.new("NumberValue") strength.Name = "Strength" strength.Value = 0 strength.Parent = leaderstats local rebirths = Instance.new("IntValue") rebirths.Name = "Rebirths" rebirths.Value = 0 rebirths.Parent = leaderstats local dataFolder = Instance.new("Folder") dataFolder.Name = player.Name dataFolder.Parent = serverStorage:WaitForChild("RemoteData") local debounce = Instance.new("BoolValue") debounce.Name = "Debounce" debounce.Parent = dataFolder local success, errormessage = pcall(function() datastore:GetAsync(player.UserId) end) if success then local LoadArray = datastore:GetAsync(player.UserId) if LoadArray then strength.Value = LoadArray[strength.Name] rebirths.Value = LoadArray[rebirths.Name] end else warn(errormessage) end player.CharacterAppearanceLoaded:Connect(function(character) local humid = character:WaitForChild("Humanoid") local bds = humid:WaitForChild("BodyDepthScale") local bhs = humid:WaitForChild("BodyHeightScale") local bws = humid:WaitForChild("BodyWidthScale") local hhs = humid:WaitForChild("HeadScale") local pbw = player:WaitForChild("Backpack"):WaitForChild("Weight") local default1 = 0.5 local default2 = 16 local base = 250 local p1 = default1 + (strength.Value / base) local s1 = default2 + (strength.Value / base) bds.Value = p1 bhs.Value = p1 bws.Value = p1 hhs.Value = p1 humid.WalkSpeed = s1 strength:GetPropertyChangedSignal("Value"):Connect(function() local p2 = default1 + (strength.Value / base) local s2 = default2 + (strength.Value / base) bds.Value = p2 bhs.Value = p2 bws.Value = p2 hhs.Value = p2 pbw.Handle.Size = Vector3.new(p2, p2, p2) humid.WalkSpeed = s2 end) end) end) game:GetService("Players").PlayerRemoving:Connect(function(player) local lead = player:WaitForChild("leaderstats") local str = lead:WaitForChild("Strength") local reb = lead:WaitForChild("Rebirths") local SaveArray = {} SaveArray[str.Name] = str.Value SaveArray[reb.Name] = reb.Value local success, errormessage = pcall(function() datastore:SetAsync(player.UserId, SaveArray) end) if not success then warn(errormessage) end end)
MouseButton1Click does not have a player variable. Instead, use the localplayer:
local delete = game:GetService("ServerStorage") player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() --first lets check if the player exists: print("Player", player) --Now let's check if we're getting the player's userId exists print("UserId", player.UserId) --Lastly, we're checking if the player.UserId exists in the serverstorage print(delete:FindFirstChild(player.UserId)) delete:FindFirstChild(player.UserId).Parent = workspace wait(1) delete:FindFirstChild(player.UserId).Parent = delete script.Parent.Parent.TextLabel.Text = "Deleted" wait(1.5) script.Parent.Parent.Visible = false script.Parent.Parent.TextLabel.Text = "Are You Sure? This Will Delete All Your Data?" end)