rexhawk suggested I should use remote events and I just started learning these. He cleaned up my script and added a lot of code for me which I thank him for. However, I'm left stranded trying to debug the server side script. The local script sends a clicked player to a server script, so it can be sent to their client and they can buy something.(Purchase weapon from player) local script under StarterPlayerScripts:

--// Services
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local Player = game.Players.LocalPlayer
--// Objects
local player = players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
 if mouse.Target.Parent:FindFirstChild("Humanoid") then
	local Need = mouse.Target.Parent
    if Player and Player.TeamColor.Name == ("Dirt brown") then
        replicatedStorage:WaitForChild("SellPistol"):FireServer(Need)
    end
end
end)

replicatedStorage:WaitForChild("SellPistol").OnClientEvent:Connect(function()
    player:WaitForChild("PlayerGui").StartScreen.Frame.Visible = true
print("test3")
end)

Script under ServerScriptService:

--// Services
local replicatedStorage = game:GetService("ReplicatedStorage")

replicatedStorage:WaitForChild("SellPistol").OnServerEvent:Connect(function(Need)
	print("test2")
    game:GetService("ReplicatedStorage"):WaitForChild("SellPistol"):FireClient(Need)
end)

--Edit I got everything the way I want it except the gui opens for the player who click not the other player

8 comments

0

Try moving the script from the ServerScriptService to the StarterGui

0

Scripts under StarterPlayerScripts only execute once.

0

Maybe show us the output aswell?

0

When you fireclient from a script you need to include a player object

0

When you fireserver you dont need to include a player object. https://developer.roblox.com/en-us/api-reference/function/RemoteEvent/FireServer

0

You can also print the parameters of OnServerEvent/OnClientEvent. print(subject) or print(subject.Name)

0

In your server script line 6, try to have player, subject as your parameters instead of having subject be the only parameter.