Hello people of the internet! I recently started to make a sandbox tycoon game, i want to know how to make a preview. (Also, if you could keep it usable with my currentbuilding setup.)
I've done a bit of research, and couldn't find a way to do it. Thanks in advance!
How my building system look right now
Replicated Storage(For those ones who want to mimic my current setup)
SERVER SCRIPT
local place = game:GetService("ReplicatedStorage").Placement.Remotes.Place
game.ReplicatedStorage.Placement.Remotes.Place.OnServerEvent:Connect(function(plr, building, position)
-- Are you kidding me, you guy not indenting properly is trigger my OCD
local position2 = position
local building2 = building:Clone()
building2.Parent = workspace
building2:MoveTo(position2)
end)
LOCAL SCRIPT
local player = game:GetService("Players").LocalPlayer -- Define the player
local mouse = player:GetMouse() -- Define the mouse
local UIS = game:GetService("UserInputService") -- UIS for activate of placement
local active = true -- Is placement active?
local activekeycode = Enum.KeyCode.E -- When the player presses E, they start placement.
local event = game:GetService("ReplicatedStorage").Placement.Remotes.Place
local changeevent = game:GetService("ReplicatedStorage").Placement.Remotes.ChangeBuilding
local currentbuilding = game:GetService("ReplicatedStorage").Placement.Buildings.Model
UIS.InputBegan:Connect(function(input, gp) --Change if it is active or not
if input == activekeycode and gp and active == true then
active = true
else
active = false
end
end)
mouse.Button1Down:Connect(function()--Start the placement
if active == true then -- Ensure it is active
print("Activated")
local building = currentbuilding
local position = mouse.Hit.p -- Don't know if i should use "mouse.Hit.p" or "mouse.Hit"
event:FireServer(building, position)
end
end)
changeevent.OnClientEvent:Connect(function(building)-- Change building
if not active == false and building ~= currentbuilding then -- Ensure it is not active
currentbuilding = building
end
end)
mouse.Move:Connect(function() -- Basically my preview
if active == true then
local position = mouse.Hit.p
local building = currentbuilding:Clone()
building.Parent = workspace
building:MoveTo(position)
local parts = building:GetChildren()
parts.Transparency = 0.4
end
end)

1 comment
It works, thanks! Few problems here and there, but overall really good.