Trying to make a part turn yellow server based with remote events

Hello, my aim is the title, don’t want it to be client based

My issue that the block doesn’t turn yellow

I have tried looking at past scripts to see how i made my deletion tool server based and it helped me with the building blocks of the script but then i got stuck as it isnt working how i intend it to

this is the script in the local script

local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
player = game.Players.LocalPlayer

local MakeYellow = game.ReplicatedStorage:WaitForChild("MakeYellow")
local plr = game:GetService("Players").PlayerAdded:Wait()
local part = game.Workspace.Context

local function onbuttonpress()
	MakeYellow:FireServer(player)
end

this is the script in the server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")

local MakeYellow = game.ReplicatedStorage:WaitForChild("MakeYellow")
local plr = game:GetService("Players").PlayerAdded:Wait()

local function onbuttonpress()
	MakeYellow.BrickColor = BrickColor.new("New Yeller")
end

MakeYellow.OnServerInvoke:Connect(function(player, NewYellow)
	ContextActionService:BindAction("Turn Brick Yellow", onbuttonpress, true, "t")
	ContextActionService:SetPosition("Turn Brick Yellow", UDim2.new(-0.2,-0.5,-0.5,-5))
	ContextActionService:SetImage("Turn Brick Yellow", "http://www.roblox.com/asset/?id=494647698")
end)

if you need any more details, like the remote function name then please let me know as im not entirely sure if u need it or not since its put in the script itself

Use .OnServerEvent instead. Invoke is for RemoteFunction, Event is for RemoteEvent.

1 Like

oh wait yeah im using functions lol

This is how you connect to RemoteFunctions:

-- In a server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteFunction = ReplicatedStorage.RemoteFunction

function remoteFunction.OnServerInvoke(player, name)
	print("Hi, my name is", name, "and this invocation came from", player.Name)
	return player.Name
end
2 Likes

how would i integrate this to what im trying to do, i think the player variable would stay there but what would name be changed to?

If the remote function is specific to…changing a part to the color yellow…you don’t need any other argument. But if the player is saying which part is yellow, then you could use the part as the argument. You can add arguments as you need them.

You don’t need to fire the player as an argument. The OnServerInvoke/OnServerEvent automatically has the player as the first argument.

it still doesnt work :smiling_face_with_tear: does it work with events instead of events or

Why do you need to use a RemoteFunction? They should only be used if the client is asking the server for data.

1 Like

i just thought thats what i need to use to make it server sided not client

Try using RemoteEvents instead, and utilize OnServerEvent:Connect() and :FireServer().

1 Like

oki i tried that and it didnt work

On the server side you create a new button but you cant do that from the server.

Instead, call those context action service functions from the client and have them fire the remoteevent. On the server, just change the parts color directly

ok so i did this on the client sided script

local function onbuttonpress()
	ContextActionService:BindAction("Turn Brick Yellow", onbuttonpress, true, "t")
	ContextActionService:SetPosition("Turn Brick Yellow", UDim2.new(-0.2,-0.5,-0.5,-5))
	ContextActionService:SetImage("Turn Brick Yellow", "http://www.roblox.com/asset/?id=494647698")
	MakeYellow:FireServer()
end

and this on the server sided script

MakeYellow.OnServerInvoke:Connect(function(player, MakeYellow)
	part.BrickColor = BrickColor.new("New Yeller")
end)

and it doesnt work, whats wrong with it?

You can’t use the FireServer method on a RemoteFunction. Use InvokeServer instead.

MakeYellow:InvokeServer()

Ooh, and if you’re using a RemoteEvent already, there is no event called OnServerInvoke for it but OnServerEvent

okay thanks ill try this tomorrow when I get back on and see how it goes

Ok good but take those ContextActionService functions out of onbuttonpress and simply place them after the function is defuned after the end keyword.

ok so i got back on and redid some things to the code, taking the contextaction service functions and stuff but it still isnt working :smiling_face_with_tear:

Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
part = game.Workspace.Context
local MakeYellow = game.ReplicatedStorage:WaitForChild("Yellow")
local plr = game:GetService("Players").PlayerAdded:Wait()

local function onbuttonpress()
	MakeYellow.BrickColor = BrickColor.new("New Yeller")
end

ContextActionService.OnServerInvoke:Connect(function(player, MakeYellow)
	part.BrickColor = BrickColor.new("New Yeller")
end)

Local

local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
player = game.Players.LocalPlayer

local MakeYellow = game.ReplicatedStorage:WaitForChild("Yellow")
local plr = game:GetService("Players").PlayerAdded:Wait()
local part = game.Workspace.Context

local function onbuttonpress()
end
ContextActionService:BindAction("Turn Brick Yellow", onbuttonpress, true, "t")
ContextActionService:SetPosition("Turn Brick Yellow", UDim2.new(-0.2,-0.5,-0.5,-5))
ContextActionService:SetImage("Turn Brick Yellow", "http://www.roblox.com/asset/?id=494647698")
ContextActionService:InvokeServer()
1 Like

Is this made by ChatGPT by any chance? This API doesn’t exist or make sense …

Anyways, here is how to do this:

  • On the client, bind your function that signals the server to your keybind
  • On the server, bind your remote event to a function that sets the brick’s color to yellow

Here is some example code:

Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local part = game.Workspace.Context
-- Instances are lower cased
local makeYellow = game.ReplicatedStorage:WaitForChild("Yellow")

local function makeBrickYellow()
	-- Edit: had a typo here.
	part.BrickColor = BrickColor.new("New Yeller")
end

-- When the client signals, run the makeBrickYellow function
makeYellow.OnServerEvent:Connect(makeBrickYellow)

Client

local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer

local makeYellow = game.ReplicatedStorage:WaitForChild("Yellow")
-- This line is classic ChatGPT ;) (humans usually don't define player twice)
--local plr = game:GetService("Players").PlayerAdded:Wait()
--local part = game.Workspace.Context

local function onbuttonpress()
	-- The fire server function sends the parameters to the server
	-- (This one has no parameters)
	makeYellow:FireServer()
end
-- Didn't really check this code, it looks correct. Might want to check the button placement
ContextActionService:BindAction("Turn Brick Yellow", onbuttonpress, true, "t")
ContextActionService:SetPosition("Turn Brick Yellow", UDim2.new(-0.2,-0.5,-0.5,-5))
ContextActionService:SetImage("Turn Brick Yellow", "http://www.roblox.com/asset/?id=494647698")
-- Also classic ChatGPT
--ContextActionService:InvokeServer()
2 Likes

is chatGPT slang for like spaghetti code? never heard the term before

okay im gonna try the code now and see how it goes. the way you explained it kinda makes sense and im gonna change it to a server event too

i just checked it on both pc and mobile, the button appears so i dont think thats the problem, however the part itself doesnt change colour

2 Likes