Top.Mail.Ru
Ответы

В чем ошибка? (Roblox Studio)

У меня есть два скрипта. Первый:

1234567891011121314151617181920212223
 -- Создаем переменную для баланса 
local Players = game:GetService("Players").PlayerAdded.leaderstats.Balance 
 
local sound = script.Parent.ImageButton.Sound 
local balance = game.Players.PlayerAdded.leaderstats.Balance 
 
-- Получаем ImageButton и TextLabel 
local imageButton = script.Parent.ImageButton 
local textLabel = script.Parent.TextLabel 
 
-- Устанавливаем начальное значение баланса 
balance.Value = 0 
 
-- Функция, которая вызывается при нажатии на ImageButton 
local function increaseBalance() 
	balance.Value = balance.Value + 1 
	textLabel.Text = "Баланс: " .. balance.Value 
	sound:Play() 
end 
 
-- Привязываем функцию к событию MouseButton1Click 
imageButton.MouseButton1Click:Connect(increaseBalance) 
 

Второй:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
 --//Datastore Script: 
 
--//Datastore 
local DataStoreService = game:GetService("DataStoreService") --Gets the DataStoreService 
local dataStore = DataStoreService:GetDataStore("Test") --Gives the Datastore a name 
 
--//Function 
local function saveData(player) --Create out own function for saving data 
	local tableToSave = { --Creates a table for our values 
		player.leaderstats.Balance.Value; --Saves the first valuee 
	} --You can continue the list in the same order by adding "player.leaderstats.IntValueName.Value;" 
 
	local success, errorMessage = pcall(dataStore.SetAsync, dataStore, player.UserId, tableToSave) --Checks if datastore succeeded 
 
	if success then --If datastore success then 
		print("Data has been saved!") --Prints success 
	else --If datastore fails then 
		print("Data has not been saved!") --Prints failure 
	end 
end 
 
--//leaderstats 
game.Players.PlayerAdded:Connect(function(player) --When a player joins the game 
	player.CharacterAdded:Wait() --Wait for the player to load 
	local leaderstats = Instance.new("Folder") --Creates a new folder for the player 
	leaderstats.Name = "leaderstats" --Sets Folder name to "leaderstats" --MAKE SURE YOU DON'T CHANGE THIS 
	leaderstats.Parent = player --Puts the Folder under the player 
 
	local points = Instance.new("IntValue") --Creates an IntValue 
	points.Name = "Balance" --Sets IntValue name to "Points" (If you change this make sure you change all of them) 
	points.Parent = leaderstats --Puts the IntValue under the "leaderstats" folder 
	points.Value = player.leaderstats.Balance.Value --Gives the IntValue Value to start off with 
 
	local data = nil --Data is empty 
 
	local success, errorMessage = pcall(function()  
		data = dataStore:GetAsync(player.UserId) --Finds the player's UserId and data 
	end) 
 
	if success and data then --If UserId and Data found then 
		points.Value = data[1] --Sets points to the first set of data 
	else --If UserId or Data not found then 
		print("The Player has no Data!") --Player has no data 
		warn(errorMessage) 
	end 
end) 
 
game.Players.PlayerRemoving:Connect(function(player) --When player is leaving the game 
	saveData(player) --Save the player's data 
end) 
 
game:BindToClose(function() --When the game's servers are shutting down 
	for _, player in ipairs(game.Players:GetPlayers()) do --loop through all the players in the server 
		task.spawn(saveData, player) --save all the player's data 
	end 
end) 

При запуске игры вылазит такая ошибка:

1
 leaderstats is not a valid member of RBXScriptSignal 
По дате
По рейтингу
Аватар пользователя
Мастер

Я как увидел первый код, меня чуть инфаркт не хватанул.
game:GetService("Players").PlayerAdded - это функция, которую надо подключать через Connect, как во втором скрипте.
ИИ Ботики писать коды конечно помогают, но доверять им вообще нельзя.

Аватар пользователя
Мастер
1234567891011121314
 local Players = game:GetService("Players").PlayerAdded.leaderstats.Balance - неправильно


local leaderstats; 
game.Players.PlayerAdded:Connect(function(plr) 
	local leader = plr:WaitForChild("leaderstats"):WaitForChild("Balance") 
	leaderstats = leader 
	end) 
 
wait(3) 
if leaderstats == nil then 
	warn("leaderstats not found") 
end 
print(leaderstats) -- проверяем, нашел ли скрипт статы 

можете подредактировать его, лично у меня он выдавал валюту, удачи!