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)
--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.
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
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)
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.