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
-- 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
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.
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 got back on and redid some things to the code, taking the contextaction service functions and stuff but it still isnt working
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()
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()