Client-side and Server-side

Hello,

As the title says I got a problem with my LocalScripts and Scripts. In the workspace I have Scripts and in StarterPlayerScripts I got LocalScripts. Now these two scripts are connected with RemoteEvents.

The LocalScript can only acces the Backpack or I just don’t know how to acces it with a normal Script. So I used a RemoteEvent so the LocalScript can acces the Backpack and clone the tool into the player’s backpack. But then ofcourse the tool isn’t visible to other players.

Anyone know how to solve this?

Here are the clips

The player himself can see the tool;

And the other player can’t;

are you giving the tool on the client?

if you use a remoteevent, OnServerEvent functions already come with a player value on default


RemoteEvent.OnServerEvent:Connect(function(player)
local Backpack = player.Backpack

end)

Yes, cause I can’t acces the backpack from the script in the workspace.

Here’s the script;

local rep = game:GetService("ReplicatedStorage")
local RemoteEvent = rep.ProximityPrompt_Screen

local function accesBackpack()
	local Players = game:GetService("Players")
	local player = Players.LocalPlayer

	local tool = Instance.new("Tool")
	tool.Parent = player.Backpack
	local screen = game.Workspace.TvParts.OldTv.Screen

	local screen_Clone = screen:Clone()
	screen_Clone.Name = "Handle"
	screen_Clone.Parent = tool
	screen:Destroy()
	
	local LocalScript_Cl = game.StarterPlayer.StarterCharacterScripts.LocalScript:Clone()
	LocalScript_Cl.Disabled = false
	LocalScript_Cl.Name = "EquipCheck"
	LocalScript_Cl.Parent = player.Backpack.Tool
	
	local official_Script = game.StarterPlayer.StarterCharacterScripts.LocalScript
	official_Script:Destroy()

	
	
	for i, v in pairs(screen_Clone:GetChildren()) do
		if v.Name == "ProximityPrompt" then 
			v:Destroy()
		end
	end
end

RemoteEvent.OnClientEvent:Connect(accesBackpack)

if you are using a proximtyprompt

ProximtyPrompt.Triggred:Connect(function(player)
local Backpack = player.Backpack


end)

also, how are you firing the client? you need a player value to fire that.


local rep = game:GetService("ReplicatedStorage")
local RemoteEvent = rep.ProximityPrompt_Screen
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local prxmity = script.Parent
	
local function TriggerAction(prompt, player)
	RemoteEvent:FireClient(prompt, player)
end


prxmity.TriggerEnded:Connect(TriggerAction)

You mean on the Script?

If I do that won’t I need Remote Events? Can I just put the code in that and then can I still clone the tool into the player’s backpack?

When you trigger a remote event for Client → server, use :FireServer instead of :FireClient

Also please note you can only reference LocalPlayer on LocalScripts. In scripts on the server, please use PlayerAdded or get the player from a remote which it seems you may be able to do.

How do I use PlayerAdded if the player already is ini the game for a couple of minutes? And does that solves my problem that the tool is visible for everyone?

When firing a RemoteEvent, the player is a default argument that you cannot remove, so lets say you had a:

RemoteEvent
Tool

If I (for example) want to give a player a tool from a trigger in the client (a gui button is a good example) I would run RemoteEvent:FireServer(Tool) assuming this stuff is already defined.

On the server, I would use RemoteEvent.OnServerEvent:Connect(function(player, tool) because the player is always included. It should be noted you can rename player to whatever you want on the server’s end, because it pretty much only cares about the order that the arguments come in. You could name it player, plr, whatever you want really, its just good practice to ensure you can identify it easily, that’s why I stick with plr.

I recommend you read up on the docs regarding remote events here: Bindable Events and Functions | Roblox Creator Documentation

I recommend using this method for getting your player.

– For future reference –
PlayerAdded is good to use at the start of your script, then inside of this function you wait for your event to happen. Even though the player is already in the game, the event inside will still trigger and it allows you to identify the Player.

Ok, but my script is inside an ProximityPrompt which is in the Workspace, and Remote Events are for Server-Client and Client-Server and thats now what I want so in theory I need to use BindableEvents or its not even necessary to use an Event nor a Function. Am I right?

If that’s the case I wouldn’t say its necessary to use any event, just simply run the function that gives the player the tool within that script.

1 Like

Thanks for your help, also thanks for being patient!

1 Like