I’m making a block building game and I’m running into trouble with letting the player change the properties of the block they want to place. The way its handled is that a UI will affect a set of properties in a table from a module and uses functions from it to set it to the player.
The client SHOULD be getting it to send to the server, but it’s not working for some reason.
local function ApplyBlockProperties(newBlock, properties)
for propName, value in pairs(properties) do
if typeof(value) == "boolean" then
if newBlock[propName] ~= nil then
local success, err = pcall(function()
newBlock[propName] = value
end)
if not success then
warn("[ApplyBlockProperties] Failed to set", propName, err)
end
end
elseif typeof(value) == "number" then
if newBlock[propName] ~= nil then
local success, err = pcall(function()
newBlock[propName] = value
end)
if not success then
warn("[ApplyBlockProperties] Failed to set", propName, err)
end
end
end
end
end
- Which is called like this
if properties then
ApplyBlockProperties(newBlock, properties)
end
The client gets the values like this:
local moduleValues = BlockPropertiesModule.GetProperties(player)
local PlayerProperties = {}
for categoryName, props in pairs(BlockPropertiesModule) do
if type(props) == "table" then
for _, prop in ipairs(props) do
if moduleValues[prop.Name] ~= nil then
PlayerProperties[prop.Name] = moduleValues[prop.Name]
else
PlayerProperties[prop.Name] = prop.Default
end
end
end
end
- Which then sends it to the server like this:
local propertiesToSend = {}
for k,v in pairs(PlayerProperties) do
propertiesToSend[k] = v
end
print("[DEBUG] Sending Properties:", propertiesToSend)
PlaceBlock:FireServer(worldPos, color, material, shape, rotationX, rotationY, propertiesToSend)
I’m stuck and sorry if this is too hard to read or described poorly. I’m trying my best to fix this crap. Please give me feedback, thank you!