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)

1 comment
@ItzFrostTheWolf right after I posted this I found this in the code and I fixed it, but it is really glitchy now but works. Thanks!