How to make a script independent for all players

Hi, first I present you what I am trying to get. The goal is to get an item from object A in the picture and then press E on object B and earn money. It’s like a delivery system in a way.

Capture d’écran 2022-08-05 111108

The problem is that when I take the item (a cardboard) from object A, all the other players can’t take a cardboard anymore and have to wait for me to put it on object B (the shelf) to be able to take a cardboard in their turn.

This problem is probably related to the fact that the script makes sure that a player cannot take several cards at the same time. Except that it works but not independently for each player.

Script from object A

local prp = script.Parent
local cardboard = game.ServerStorage.Cardboard

prp.Triggered:Connect(function(player)
	cardboard:Clone()
	cardboard.Parent = player.Backpack
	game.StarterPlayer.cardboard.Value = true
	prp.Enabled = false
end)

Script from object B

local cardboardtool = game.ServerStorage.Cardboard
local BoxStock = game.Workspace.BoxStock
local prp = script.Parent
local customer = prp.Parent

script.Parent.Triggered:Connect(function(player)
	if game.StarterPlayer.cardboard.Value == true then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + 5
		game.StarterPlayer.cardboard.Value = false
		cardboardtool.Parent = game.ServerStorage
		wait(5)
		game.Workspace.BoxStock.ProximityPrompt.Enabled = true
	end
end)

Thanks in advance to those who will help me :slight_smile:

3 Likes

It may work if you fire a RemoteEvent using :FireClient(), and disabling the prompt there

You can just put the script in the client.

How to put the script in the client ? :sweat_smile:

You shouldn’t just disable the prompt as the client will be able to enable it using exploits.

Never trust the client. You should always do sanity checks on the server.

so, how can I do that, can you show me?

It’s just a project, so I didn’t get sophisticated

Let’s try to make the script support multiple players in the first place.

Here’s an example what you can do in script A:

  1. Instead of using the same carboard box, :Clone() it
  2. Make an ObjectValue that refers to the cloned box and put the ObjectValue into player’s character
  3. Make your script check for the aforementioned ObjectValue before giving out another cardboard box. If it’s present, then don’t

Meanwhile in script B:

  1. If the ObjectValue is present in the player’s character, :Destroy() the box it’s referring to and the value itself, so that script A can give another box, and give money to the player.

(The reason why I suggest putting the value in Character is so that the value gets destroyed after the player resets, since the box does not persist after the character dies)

1 Like