#I can't figure out how to get this script to work.

17 messages · Page 1 of 1 (latest)

upbeat phoenix
#

so I am pretty good at building but I'm trash at scripting so I apologize if something doesn't work at all. The script is supposed to recognize when robux is spent, then the script should check a folder in serverstorage titled "npcs" and get a npc called dummy and spawn it underneath a part called Spawner. I can't figure out how to get it to detect the purchase and spawn the npc. If needed I will add more description. Here is the script: https://pastebin.com/bjNehjK9

zealous egret
#

This script listens for the "PromptPurchaseRequested" event from the "MarketplaceService" to detect when the player spends Robux. It adds the price to the "robuxSpent" variable, and then calls the "spawnNpc" function which creates a new NPC object called "dummy" and a part called "Spawner" under it in the "npcs" folder in "ServerStorage." It then repeats the process for each Robux spent. However, this script has some issues. It creates multiple "dummy" NPC models, each with its own "Spawner" part, and it will not work as expected since the spawnNpc function is called only once when the script starts and not every time the player spends Robux. To fix it, you can move the call to the spawnNpc function inside the "PromptPurchaseRequested" event listener.

#

I ain't scripta

#

it's chatgpt's text

#

“`
-- local variable to store the amount of robux spent
local robuxSpent = 0

-- bind an event to detect when robux is spent
game:GetService("MarketplaceService").PromptPurchaseRequested:Connect(function(player, assetId, price)
-- update the amount of robux spent
robuxSpent = robuxSpent + price
-- call the spawn function when robux is spent
spawnNpc()
end)

-- create the NPC spawn function
local function spawnNpc()
-- create a new NPC object
local npc = Instance.new("Model")
npc.Name = "dummy"
npc.Parent = game:GetService("ServerStorage").npcs

-- create a part to serve as the NPC's spawn location
local spawner = Instance.new("Part")
spawner.Name = "Spawner"
spawner.Parent = npc

end
` “

#

that's from chatgpt too

#

i dunno if it's wrong or true you're the scripter try

sturdy thorn
#
Code here
zealous egret
#
-- local variable to store the amount of robux spent
local robuxSpent = 0

-- bind an event to detect when robux is spent
game:GetService("MarketplaceService").PromptPurchaseRequested:Connect(function(player, assetId, price)
    -- update the amount of robux spent
    robuxSpent = robuxSpent + price
    -- call the spawn function when robux is spent
    spawnNpc()
end)

-- create the NPC spawn function
local function spawnNpc()
    -- create a new NPC object
    local npc = Instance.new("Model")
    npc.Name = "dummy"
    npc.Parent = game:GetService("ServerStorage").npcs

    -- create a part to serve as the NPC's spawn location
    local spawner = Instance.new("Part")
    spawner.Name = "Spawner"
    spawner.Parent = npc
end
zealous egret
#

wanted to help

zealous egret
sturdy thorn
#

so what does it do

zealous egret
#

i dunno