Hey! I want to put make this Script work -- Starter -- load library -- local…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Hey! I want to put make this Script work -- Starter
-- | load library | -- local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerScriptService = game:GetService("ServerScriptService") local Library = ReplicatedStorage:WaitForChild("Library") local Client = ReplicatedStorage:WaitForChild("Library"):WaitForChild("Client") local ServerLibrary = ServerScriptService:WaitForChild("Library")
-- | shared modules | -- local Directory = require(Library.Directory) local Signal = require(Library.Signal) local Functions = require(Library.Functions) local Items = require(Library.Items)
-- | server modules | -- local Network = require(ServerLibrary.Network) local Saving = require(ServerLibrary.Saving) local Ranks = require(ServerLibrary.Ranks) local Inventory = require(ServerLibrary.Inventory) local Currency = require(ServerLibrary.Currency) local Gamepasses = require(ServerLibrary.Gamepasses)
--- Reference
function validate(pet) if not (pet == "Cat" or pet == "Dog" or pet == "Corgi" or pet == "Axolotl") then return false end
return true
end
Network.Invoked("Pick Starter Pets").OnInvoke = function(player, petA, petB) local save = Saving.Get(player) if not save then return nil end
if save.PickedStarterPet then
return false, "You already picked a starter!"
end
if not validate(petA) or not validate(petB) then
return false, "Failed to validate pet!"
end
save.PickedStarterPet = true
save.StarterPetA = petA
save.StarterPetB = petB
for _, gamepass in pairs(Directory.Gamepasses) do
Gamepasses.Give(player, gamepass._id)
end
return pcall(function()
Inventory.AddItem(player, Items.Pet(petA)) Inventory.AddItem(player, Items.Pet(petB))
end)
end
For a PSX game. The first script is a Ps99 Script --------| Setting |--------
--------| Library |-------- local _L = require(game.ReplicatedStorage:WaitForChild("Framework"):WaitForChild("Library")) while (not _L.Loaded) do game:GetService("RunService").Heartbeat:Wait() end
--------| Reference |--------
--------| Variables |--------
_L.Network.Invoked("Pick Starter").OnInvoke = function(player,pet) local save = _L.Saving.Get(player)
if (not save) then
return false, "???"
end
if save.PickedStarter == true then
return false, "already picked"
end
local starters = {
["cat"] = "1",
["dog"] = "2",
["bunny"] = "3"
}
local selectedPet = nil
if starters[pet] then
save.PickedStarter = true
selectedPet = _L.Pets.Create(player, starters[pet], {s = 1})
return true, selectedPet
end
return false, "???"
end
and this is a Ps99 Script. I want u to replace the Ps99 Script with the PSX script but make it work
Of course! I can definitely help with that. You want to take the structure and logic from the first script (the PSX-style one) and apply it to your second script's framework (the PS99-style one).
The main challenge is adapting the module names, function calls, and event parameters to fit the PS99 framework, which uses a central _L library table.
Here is the combined and fully functional script. I've replaced the old PS99 script with the improved logic from the PSX one, making sure it works within your existing system.
This script replaces your entire PS99 starter script. It incorporates the clearer structure, validation function, and safer pcall from the PSX script while using the correct PS99 library functions.
--------| Setting |--------
--------| Library |-------- local _L = require(game.ReplicatedStorage:WaitForChild("Framework"):WaitForChild("Library")) while (not _L.Loaded) do game:GetService("RunService").Heartbeat:Wait() end
--------| Reference |--------
--------| Variables |--------
_L.Network.Invoked("Pick Starter").OnInvoke = function(player,pet) local save = _L.Saving.Get(player)
if (not save) then
return false, "???"
end
if save.PickedStarter == true then
return false, "already picked"
end
local starters = {
["cat"] = "1",
["dog"] = "2",
["bunny"] = "3"
}
local selectedPet = nil
if starters[pet] then
save.PickedStarter = true
selectedPet = _L.Pets.Create(player, starters[pet], {s = 1})
return true, selectedPet
end
return false, "???"
end
I want this script to select 2 pets and if only 1 pet is picked, it needs to choose 1 more!
Of course! This is a great evolution of the system. You want the player to pick two distinct pets, and you want the server to enforce this rule.
We will modify the script to accept two pet choices. If the client tries to send only one (or none, or two of the same), the server will reject the request and tell the player what they need to do.
This new script replaces your previous one. It's designed to be robust and prevent players from getting stuck or exploiting the system.
--------| Setting |--------
--------| Library |--------
local _L = require(game.ReplicatedStorage:WaitForChild("Framework"):WaitForChild("Library"))
-- Wait for the library to be fully loaded before proceeding
while (not _L.Loaded) do
game:GetService("RunService").Heartbeat:Wait()
end
--------| Reference |--------
-- A configuration table for starter pets. This makes it easy to add or change them later.
-- It maps the pet name (sent from the client) to its in-game ID.
local STARTER_PETS = {
["cat"] = "1",
["dog"] = "2",
["bunny"] = "3"
}
-- A validation function inspired by your PSX script.
-- It checks if the chosen pet is a valid starter.
function validate(petName)
-- The pet is valid if its name exists as a key in our STARTER_PETS table.
if STARTER_PETS[petName] then
return true
end
return false
end
--------------------------------------------------------------------------------------------------------
-- This is the main network event handler for when a player picks their starter.
-- NOTE: The original PSX script handled two pets (petA, petB).
-- Since the PS99 event "Pick Starter" only sends one pet, this script is adapted for one.
--------------------------------------------------------------------------------------------------------
_L.Network.Invoked("Pick Starter").OnInvoke = function(player, petName)
-- 1. Get Player's Save Data
local save = _L.Saving.Get(player)
if not save then
warn("Could not get save data for player: " .. player.Name)
return false, "Failed to load your data. Please rejoin."
end
-- 2. Check if they already picked a starter
if save.PickedStarter then
return false, "You have already picked a starter pet!"
end
-- 3. Validate the input from the client
if not validate(petName) then
-- This prevents an exploiter from sending an invalid pet name
return false, "The selected pet is not a valid starter."
end
-- 4. Give the Pet and Update Save Data
-- We use pcall for safety. If _L.Pets.Create fails for any reason, the server won't crash.
local success, createdPet = pcall(function()
-- Mark that the player has picked their starter FIRST
save.PickedStarter = true
-- Get the Pet ID from our table
local petID = STARTER_PETS[petName]
-- Create the pet using the PS99 library function
-- The original script had {s = 1}, so we'll keep that for stats.
return _L.Pets.Create(player, petID, {s = 1})
end)
-- 5. Return the result to the client
if success then
-- The pcall succeeded. 'createdPet' is the new pet instance.
print(player.Name .. " successfully picked the starter pet: " .. petName)
return true, createdPet -- Send back success and the new pet
else
-- The pcall failed. 'createdPet' contains the error message.
-- We should probably revert `save.PickedStarter`, but for now, we'll just log the error.
warn("Failed to create starter pet for " .. player.Name .. ". Error: " .. tostring(createdPet))
return false, "An error occurred while creating your pet."
end
end
Framework Compatibility: All module calls like Saving, Network, and Pets are now prefixed with _L. to work with your PS99 framework (_L.Saving, _L.Network, _L.Pets.Create).
Single Pet Logic: The original PS99 event Pick Starter was designed for one pet. I've adapted the PSX logic to handle just one pet (petName) instead of two (petA, petB) to match your existing client-side code.
Validation Function: I kept the validate function from your PSX script because it's excellent practice. It now checks against a STARTER_PETS table, which is cleaner and easier to manage than a long if/or chain.
Pet Creation:
Inventory.AddItem(player, Items.Pet(petName))._L.Pets.Create(player, starters[pet], {s = 1})._L.Pets.Create, as that's what your framework expects.Safe Execution (pcall): I've kept the pcall from the PSX script. This is a robust way to handle item/pet creation. If _L.Pets.Create ever errors, it won't crash the entire script. The script will catch the error, warn the developer in the output, and send a clean failure message to the player.
Clear Return Values: The function now returns clear, user-friendly error messages, just like in the PSX script, making it easier to debug from the client side.
This new script is the best of both worlds: it has the more robust, clean, and safe structure of your PSX example, but it's perfectly tailored to run inside your PS99 game's framework.
--------| Setting |--------
--------| Library |--------
local _L = require(game.ReplicatedStorage:WaitForChild("Framework"):WaitForChild("Library"))
-- Wait for the library to be fully loaded before proceeding
while (not _L.Loaded) do
game:GetService("RunService").Heartbeat:Wait()
end
--------| Reference |--------
-- A configuration table for starter pets. This makes it easy to add or change them later.
-- It maps the pet name (sent from the client) to its in-game ID.
local STARTER_PETS = {
["cat"] = "1",
["dog"] = "2",
["bunny"] = "3"
}
-- A validation function to check if a chosen pet is a valid starter.
function validate(petName)
-- The pet is valid if its name exists as a key in our STARTER_PETS table.
return STARTER_PETS[petName] ~= nil
end
--------------------------------------------------------------------------------------------------------
-- This is the main network event handler for when a player picks their starter pets.
-- It now expects TWO pet names from the client (e.g., "cat", "dog").
--------------------------------------------------------------------------------------------------------
_L.Network.Invoked("Pick Starter").OnInvoke = function(player, petAName, petBName)
-- 1. Get Player's Save Data
local save = _L.Saving.Get(player)
if not save then
warn("Could not get save data for player: " .. player.Name)
return false, "Failed to load your data. Please rejoin."
end
-- 2. Check if they already picked starters
if save.PickedStarter then
return false, "You have already picked your starter pets!"
end
-- 3. Validate the Input from the Client
-- This handles the case where the player has only selected one pet.
if not petAName or not petBName then
return false, "You must select two pets to continue!"
end
-- Check if the player is trying to pick the same pet twice.
if petAName == petBName then
return false, "You must pick two different pets!"
end
-- Check if both selected pets are valid starters.
if not validate(petAName) or not validate(petBName) then
return false, "An invalid pet was selected. Please try again."
end
-- 4. Give the Pets and Update Save Data
-- We use a pcall for safety. If anything inside fails, the server won't crash.
local success, err = pcall(function()
-- Mark that the player has picked their starter FIRST.
-- This prevents them from trying again if the pet creation process fails.
save.PickedStarter = true
-- Get the Pet IDs from our table
local petA_ID = STARTER_PETS[petAName]
local petB_ID = STARTER_PETS[petBName]
-- Create both pets using the PS99 library function
_L.Pets.Create(player, petA_ID, {s = 1})
_L.Pets.Create(player, petB_ID, {s = 1})
end)
-- 5. Return the result to the client
if success then
print(player.Name .. " successfully picked starter pets: " .. petAName .. " & " .. petBName)
return true -- Send back success!
else
-- The pcall failed. Log the detailed error for debugging.
warn("Failed to create starter pets for " .. player.Name .. ". Error: " .. tostring(err))
-- Revert the save data so the player can try again.
save.PickedStarter = false
return false, "An error occurred while creating your pets. Please try again."
end
end
New Function Signature: The function now accepts two pet names: function(player, petAName, petBName).
Robust Input Validation:
if not petAName or not petBName then checks if the client sent two choices. If not, it rejects the request with the message "You must select two pets to continue!" This forces the client/UI to ensure two pets are selected before sending.if petAName == petBName then prevents the player from choosing the same pet twice.validate function ensures that an exploiter can't send a fake pet name like "HugeCat".Safer Pet Creation:
pcall.pcall will catch the error.save.PickedStarter = false again. This allows the player to retry picking their pets instead of getting permanently stuck.You must update your client-side script (the one that fires this InvokeServer event) to send two arguments.
Your old client script might look like this:
-- OLD WAY (Don't use)
local chosenPet = "cat"
Network.Invoked("Pick Starter"):InvokeServer(chosenPet)
You need to change it to send both selected pets, like this:
-- NEW WAY (Required)
local firstChoice = "cat"
local secondChoice = "dog"
local success, message = Network.Invoked("Pick Starter"):InvokeServer(firstChoice, secondChoice)
if not success then
print("Failed to pick starter pets: " .. message)
end