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
local buy = script.Parent local Players = game:GetService("Players") local replicatedStorage = game:GetService("ReplicatedStorage") local buyPressed = replicatedStorage:WaitForChild("BuyPressed") buy.MouseButton1Click:Connect(function() local players = Players:GetChildren() for i = 1, #players do local player = game.Players.LocalPlayer local items = player.Backpack:GetChildren() if #items ~= 0 then player.Backpack:ClearAllChildren() buyPressed:FireServer() else buyPressed:FireServer() end end end)
Main Script
local buyPressed = game.ReplicatedStorage:WaitForChild("OnClick") local function buyItem() local result = buyTool:InvokeServer(tool, tool.Cost) if result == "BoughtItem" then print("item bought") elseif result == "NotEnoughCash" then print("not money") elseif result == "NoItemOrNoCostValue" then print("this items messed up bruh") end end buyPressed.OnServerEvent:Connect(buyItem)
On line 1 in the main script, it says you are waiting for the event "OnClick", but on the other script in line 4 you are waiting for a different event called "BuyPressed". Could this be your answer?