Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Buy Script used to work, but after a few months, it doesn't?

I went back to developing a game after a few months to find scripts broke. I fixed some by making them localscripts, but one did not work. It has no visible errors, and changes to paths do nothing. This script is unchanged from when it worked, and now no parts of it work.

--// Script for SwordMerchant or NPC shop NPC head \\--

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if choice == script.Parent.DialogChoice.BronzeSword.Yes then
		if player.leaderstats.Gold.Value >= 200 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 200
			game.ReplicatedStorage.BronzeSword:Clone().Parent = player.Backpack
			game.ReplicatedStorage.BronzeSword:Clone().Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else 
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		end
	elseif choice == script.Parent.DialogChoice.GoldenHeart.Yes then
		if player.leaderstats.Gold.Value >= 1000000 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 1000000
			game.ReplicatedStorage.GoldenHeartSword:Clone().Parent = player.Backpack
			game.ReplicatedStorage.GoldenHeartSword:Clone().Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else 
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		end
	elseif choice == script.Parent.DialogChoice.IronSword.Yes then
		if player.leaderstats.Gold.Value >= 400 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 400
			game.ReplicatedStorage.IronSword:Clone().Parent = player.Backpack
			game.ReplicatedStorage.IronSword:Clone().Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else 
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		end
	elseif choice == script.Parent.DialogChoice.SteelSword.Yes then
		if player.leaderstats.Gold.Value >= 500 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 500
			game.ReplicatedStorage.SteelSword:Clone().Parent = player.Backpack
			game.ReplicatedStorage.SteelSword:Clone().Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else 
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Parent.Disabled = false
		end
	end
end)

2 answers

✓ Accepted answer

Try doing this:

Wherever the script says Clone().Parent, make the clone a variable THEN change the parent, for example:

Sword:Clone().Parent

becomes

local clone = Sword:Clone()
clone.Parent = player.Backpack

Otherwise, im not sure if the function for the dialog is actually calling the player, so use

print(player.Name)

and see if it comes out nil in your output

I've attached a copy of the Revised Code (LocalScript)

--// Script for SwordMerchant or NPC shop NPC head \\--
local player = game.Players.LocalPlayer
local location = game.Workspace.NPC.Head.Dialog -- Wherever the Dialog location is

location.DialogChoiceSelected:Connect(function(player, choice)
	print(player.Name)
	if choice == location.DialogChoice.BronzeSword.Yes then
		if player.leaderstats.Gold.Value >= 200 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 200
			local BronzeSword1 = game.ReplicatedStorage.BronzeSword:Clone()
			BronzeSword1.Parent = player.Backpack
			local BronzeSword2 = game.ReplicatedStorage.BronzeSword:Clone()
			BronzeSword2.Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
			end
	elseif choice == location.DialogChoice.GoldenHeart.Yes then
		if player.leaderstats.Gold.Value >= 1000000 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 1000000
			local GoldenHeart1 = game.ReplicatedStorage.GoldenHeartSword:Clone()
			GoldenHeart1.Parent = player.Backpack
			local GoldenHeart2 = game.ReplicatedStorage.GoldenHeartSword:Clone()
			GoldenHeart2.Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		end
	elseif choice == location.DialogChoice.IronSword.Yes then
		if player.leaderstats.Gold.Value >= 400 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 400
			local IronSword1 = game.ReplicatedStorage.IronSword:Clone()
			IronSword1.Parent = player.Backpack
			local IronSword2 = game.ReplicatedStorage.IronSword:Clone()
			IronSword2.Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		end
	elseif choice == location.DialogChoice.SteelSword.Yes then
		if player.leaderstats.Gold.Value >= 500 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 500
			local SteelSword1 = game.ReplicatedStorage.SteelSword:Clone()
			SteelSword1.Parent = player.Backpack
			local SteelSword2 = game.ReplicatedStorage.SteelSword:Clone()
			SteelSword2.Parent = player.StarterGear
			local gui = game.ReplicatedStorage.Success:Clone()
			gui.Parent = player.PlayerGui
			gui.Script.Disabled = false
		else
			local gui = game.ReplicatedStorage.Decline:Clone()
			gui.Parent = player.PlayerGui
			gui.Parent.Disabled = false
		end
	end
end)

7 comments

0

I used the code provided, and it still does nothing. The print doesn't even go through.

0

Are you using a LocalScript or a Server Script?, and where is the script located? (script.Parent)

0

I tried both, if I use a localscript though, sometimes the Dialog will not appear above the NPC, only the choices.

0

ok, well since the print is not reading, then the function isn't giving a value for player, you need to use a local script anyway due to the nature of PlayerGui, so try adding a line above to define the player as "local player = game.Players.LocalPlayer" and see if you get the output then. Make sure that the script parent is the dialog itself

0

No luck with that change.

0

oh, since you have to use a LocalScript, the LocalScript must be placed into the StarterGui. However, by doing this, you have to edit the script.Parent to be the exact location of the dialog

0

Ok, so now it prints the player's name. Directly after this, it reads this error: "DialogChoice is not a valid member of PlayerGui" Everytime a choose an option, otherwise, it works now. Edit: It's because I didn't change paths on all parts of the script

Cloning a object has change it used to be

game.Workspace.Ex:Clone()
--or
 local thing = game.Workspace.Ex:Clone()
thing.Parent = game.Workspace.Folder
-- now its just 
 local thing = game.Workspace.Ex:Clone()
thing.Parent = game.Workspace.Folder

2 comments

1

Cerdits to serp tho put it in a answer not a comment

0

haha, thx, just switched them (i put a comment first since i wasnt sure at the time if I was right), btw though, you repeated yourself

This discussion is preserved as it was. New answers, comments, and votes are closed.