ProximityPrompt Server & Client Event

Hello, I’m trying to make a script within a proximity prompt to send a request towards a local script to change the baseplate red for all players.

Help would be cool.

Code within the ProximityPrompt (Script),

script.Parent.Triggered:Connect(function(player)
	
	game.ReplicatedStorage.RemoteEvent:FireClient(player)
	
end)

Code within the ServerScriptServices (Local Script),

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Event.OnClientEvent:Connect(function(player)
	
	game.Workspace.Baseplate.BrickColor = BrickColor.Red()
	
end)

P.S: I am just starting to learn about events.

If you want to make it turn red for all players then you’ll have to use FireAllClients() instead.
FireAllClients() - as the function name suggests - is firing that event to all players that are in the game.

If I understand correctly, you want the part to be red for everyone in the game, if so, you don’t need a RemoteEvent, just use the Script (Server) to stay right after someone starts:

local BasePart = script.Parent.Parent
local Prompt = script.Parent

Prompt.Triggered:Connect(function(player)
	BasePart.Color = Color3.fromRGB(255, 0, 0)
end)

Now, if you want to implement a Remote Event, you can use FireAllClients

Script: Server

local BasePart = script.Parent.Parent
local Prompt = script.Parent
local RemoteChangeColor = game.ReplicatedStorage.RemoteEvent

Prompt.Triggered:Connect(function(player)
	RemoteChangeColor:FireAllClients()
end)

Script: Local

local Remote = game.ReplicatedStorage.RemoteEvent
local BasePart = workspace.Part

Remote.OnClientEvent:Connect(function()
	BasePart.Color = Color3.fromRGB(255, 0, 0)
end)
2 Likes

If you want to change the baseplate red for all players you don’t need to use a local script instead you would should just have it change server side in the server script. However if you want to do it locally for each player your server script should look like this:

Server Script:

script.Parent.Triggered:Connect(function(player)
	
	game.ReplicatedStorage.RemoteEvent:FireAllClients()
	
end)

Also you have to run the Local Script inside PlayerScripts.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.