How can I change 1 script using another one?

how can I change 1 script using another one?
the script that should change the other :

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Menu = PlayerGui.Menu
local MainFrame = Menu.MainFrame
local MainMenu = MainFrame.MainMenu
local Popups = MainFrame.Popups
local Shop = Popups.Shop
local BuyScript = Shop.PassInfo.BuyButton.BuyScript
	
script.Parent.MouseButton1Click:Connect(function()
	BuyScript. --NEED CHANGE parent at BuyScript - local id = {ID}
end)

the script that needs to be changed in the ID location :

local ID = 0

local User = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

if User then

game:GetService("MarketplaceService"):PromptGamePassPurchase(User, ID)

end

end)

A script cannot be modified if its running. There are other ways to hold values without them being contained INSIDE the script.

  1. Add a IntValue inside the script and modify its Value.
  2. You can make the use of metaTables, but they are complicated for beginners.
  3. Add a bindableEvent and transfer a value from one script to the other.

What you could do is

--SCRIPT 1
local event = targetScript.BindableEvent
event:Fire(id)

--SCRIPT 2
local event = script.BindableEvent
local ID
event.Event:Connect(function(newID)
    ID = newID
end)

This uses the bindableEvent method which is the easiest to transfer values from one script to another.

1 Like

I tried to use intvalue, but alas I didn’t succeed, on the bindable event, I’ll try now.

so, I’m testing a bindable event, I can tell it doesn’t do anything

I know that if you are scripting a plugin, if you use local newScript = Instance.new("Script") then you can edit the code inside of that with newScript.Source.

I just need to change the local id when pressing a button that has its own script - when the player clicks on the button, he changes the ID of the purchase item on the 2nd purchase button

I know, but it looks like editing a Script’s source through another script will just cause an error. I know this may not answer the question fully, and there may be another way to do it, but I’m just pointing this out.

Its because you are checking the IntValue before its being changed. You need to check WHEN the Value has changed and then change the variable inside the script to the IntValue.Value

i try, so error : 23:20:38.973 MarketplaceService::PromptGamePassPurchase() was called with an invalid game pass id (supplied game pass id was less than zero) - Client - BuyScript:6
the script that changes the Int Value.Value

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Menu = PlayerGui.Menu
local MainFrame = Menu.MainFrame
local MainMenu = MainFrame.MainMenu
local Popups = MainFrame.Popups
local Shop = Popups.Shop
local BuyScript = Shop.PassInfo.BuyButton.BuyScript
	
script.Parent.MouseButton1Click:Connect(function()
	BuyScript.GamepassID.Value = "53084595"
end)

( if you’re say “53084595” the “” its error at id, i can say i try add and remove this “”)
Script with intValue

local ID = script.GamepassID.Value
local User = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if User then
		game:GetService("MarketplaceService"):PromptGamePassPurchase(User, ID)
	end
end)

and so there is some kind of answer to my yesterday?

Sorry for late response.
Is GamepassID value a valid number?
Also, if you’re using IntValue, use a NumberValue instead. IntValue value are being interpreted as strings, make sure the that in
BuyScript.GamepassID.Value = "53084595"
the gamepassID is a number instead of a string. To achieve a number instead of string, leave it outside quotations. Being like this instead:

BuyScript.GamepassID.Value = 53084595

I also recommend you making everything in the same script as the one where you click the UI Button, so you can achieve the value in the same script easier.