How would you make a function go from one script to another?
I know the title doesn't make sense, but I'm trying to make it so that when I press a button, a function in another script activates. Also, the other answers I found didn't work because both of my scripts are local scripts. Here is my code:
Button Script
01 | local buy = script.Parent |
02 | local Players = game:GetService( "Players" ) |
04 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
05 | local buyPressed = replicatedStorage:WaitForChild( "BuyPressed" ) |
07 | buy.MouseButton 1 Click:Connect( function () |
08 | local players = Players:GetChildren() |
09 | for i = 1 , #players do |
10 | local player = game.Players.LocalPlayer |
11 | local items = player.Backpack:GetChildren() |
13 | player.Backpack:ClearAllChildren() |
14 | buyPressed:FireServer() |
16 | buyPressed:FireServer() |
Main Script
01 | local buyPressed = game.ReplicatedStorage:WaitForChild( "OnClick" ) |
03 | local function buyItem() |
04 | local result = buyTool:InvokeServer(tool, tool.Cost) |
06 | if result = = "BoughtItem" then |
08 | elseif result = = "NotEnoughCash" then |
10 | elseif result = = "NoItemOrNoCostValue" then |
11 | print ( "this items messed up bruh" ) |
15 | buyPressed.OnServerEvent:Connect(buyItem) |