Hello again…
So I was trying to test an idea that came to mind about being able to place parts at the position of your cursor which is working all fine and dandy ofc. So I decided to make a more complex version of this script by allowing the player to set Materials to the part of their choice, and later on Transparency and BrickColor which seems to be way easier than Materials…
So what am I trying to achieve? I’m trying to make it so people click on one of these GUI buttons:
Which then updates this by setting a string to the Enum Material of the selected Material from the GUI which also works, and then when the player clicks it fires the server with the material name in mind:
And then when it reaches the server I’m given an error:
Here’s my 3 scripts:
Button Script
local MaterialModule = require(script.Parent.Parent.Parent.Modules.Materials)
local MaterialButton = script.Parent
local Material_Name_Attribute = script:GetAttribute("Material_Name")
-- Get the Config string value to override --
local MaterialValue = script.Parent.Parent.Parent.Config.Material
-- Get the ClickSound for extra effect :D --
local ClickSound = script.Parent.Parent.Click
MaterialButton.MouseButton1Click:Connect(function()
ClickSound:Play()
local toStringMaterial = tostring(MaterialModule[Material_Name_Attribute])
MaterialValue.Value = toStringMaterial
end)
Click To Spawn Part Script
Player = game:GetService("Players").LocalPlayer
local ConfigurationFolder = Player.PlayerGui:WaitForChild("PartConfig").Config
local MaterialConfig = ConfigurationFolder:WaitForChild("Material").Value
local BrickColorConfig = ConfigurationFolder:WaitForChild("BrickColor").Value
local TransparencyConfig = ConfigurationFolder:WaitForChild("Transparency").Value
-- Use this to check if the player disabled part placement --
local SpawnConfig = ConfigurationFolder:WaitForChild("SpawnEnabled").Value
Mouse = Player:GetMouse()
TowerPlaceEvent = game:GetService("ReplicatedStorage").TowerPlaceEvent
Mouse.Button1Down:Connect(function(mouse)
if not SpawnConfig then
-- do nothing
else
local MousePosition = Mouse.Hit.p
-- Tell Server to Place Specific Tower --
TowerPlaceEvent:FireServer(MousePosition, MaterialConfig, BrickColorConfig, TransparencyConfig, SpawnConfig) -- doesn't really need SpawnConfig, but will add anyways.
-- :)
end
end)
TowerPlaceEvent.OnClientEvent:Connect(function()
local NoGui = Player:WaitForChild("PlayerGui").No
if NoGui.Enabled == true then
-- do nothing
else
NoGui.Enabled = true
local ErrorSound = NoGui.Text.Error
NoGui.Text.Text = "Sorry but you're broke bro 😭"
ErrorSound:Play()
wait(3)
NoGui.Enabled = false
end
end)
And finally the server script which adapts all the information needed for this event with some other edits that didn’t seem to work either, hence why you see table.find
because that was for reading the official Enumerations dev hub post
TowerPlaceEvent = game:GetService("ReplicatedStorage").TowerPlaceEvent
local Materials = require(script.Materials)
local PriceOfTower = 1
TowerPlaceEvent.OnServerEvent:Connect(function(Player, MousePosition, MaterialConfig, BrickColorConfig, TransparencyConfig, SpawnConfig)
MyMoney = Player:WaitForChild("leaderstats").Bobux
if MyMoney.Value >= 1 then
local NewPartToPlace = Instance.new("Part")
local SoundToPlay = Instance.new("Sound")
SoundToPlay.SoundId = "rbxassetid://12221967"
-- Set our Configurations to our Part --
--local FoundEnum = table.find(Materials, MaterialConfig)
NewPartToPlace.Material = table.find(Materials, MaterialConfig)
NewPartToPlace.BrickColor = BrickColorConfig
NewPartToPlace.Transparency = TransparencyConfig
NewPartToPlace.Parent = workspace
NewPartToPlace.Anchored = true
NewPartToPlace.CanCollide = true
NewPartToPlace.Position = MousePosition
SoundToPlay.Parent = NewPartToPlace
SoundToPlay:Play()
MyMoney.Value = MyMoney.Value - PriceOfTower
else
TowerPlaceEvent:FireClient(Player)
print(Player.Name.." didn't have enough money")
end
end)
And this is the module script that both Server + Client (separate copies for each, was too lazy to move it over to ReplicatedStorage)
local Roblox_Materials = {
Brick = Enum.Material.Brick,
Cobblestone = Enum.Material.Cobblestone,
Concrete = Enum.Material.Concrete,
CorrodedMetal = Enum.Material.CorrodedMetal,
DiamondPlate = Enum.Material.DiamondPlate,
Fabric = Enum.Material.Fabric,
Foil = Enum.Material.Foil,
ForceField = Enum.Material.ForceField,
Glass = Enum.Material.Glass,
Granite = Enum.Material.Granite,
Grass = Enum.Material.Grass,
Ice = Enum.Material.Ice,
Marble = Enum.Material.Marble,
Metal = Enum.Material.Metal,
Neon = Enum.Material.Neon,
Pebble = Enum.Material.Pebble,
Plastic = Enum.Material.Plastic,
Sand = Enum.Material.Sand,
Slate = Enum.Material.Slate,
SmoothPlastic = Enum.Material.SmoothPlastic,
Wood = Enum.Material.Wood,
WoodPlanks = Enum.Material.WoodPlanks
}
return Roblox_Materials
Any help would be greatly appreciated on how to fix this because I’m super stumped…