I’m very new to remote events, so I apologize in advance if the code looks horrendous.
I’ll just show the scripts:
Building script (this is inside a tool):
---------------------------------------------VARIBLES-------------------------------------------------
local runService = game:GetService("RunService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 1.5
local blueBlock = game.ReplicatedStorage:WaitForChild("BlueBlock")
local shadow_block = blueBlock:Clone(); shadow_block.Transparency = .5; shadow_block.Parent = workspace.Blocks.ShadowBlocks; shadow_block.CanCollide = false
if shadow_block.CanCollide == true then
print("BRUH")
end
mouse.TargetFilter = shadow_block
---------------------------------------------FUNCTIONS-------------------------------------------------
function snapToGrid(x)
return math.floor(x/grid + 0.5)*grid
end
function calculateY(toP, toS, oS)
return (toP + toS * 0.5) + oS * 0.5
end
runService.RenderStepped:Connect(function()
if mouse.Target ~= nil then
shadow_block.Position = Vector3.new(snapToGrid(mouse.Hit.Position.X), calculateY(mouse.Target.Position.Y, mouse.Target.Size.Y, blueBlock.Size.Y), snapToGrid(mouse.Hit.Position.Z))
end
end)
mouse.Button1Down:Connect(function()
if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
local clone = blueBlock:Clone()
clone.Parent = workspace.Blocks.BlueBlocks
clone.Position = shadow_block.Position
print("script is working")
end
end)
runService.RenderStepped:Connect(function()
if tool:FindFirstAncestorWhichIsA("Model") ~= player.Character then
shadow_block.Transparency = 1
end
end)
runService.RenderStepped:Connect(function()
if tool:FindFirstAncestorWhichIsA("Model") == player.Character then
shadow_block.Transparency = 0.5
end
end)
Server script inside ServerScriptService:
local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")
remoteEvent.OnServerEvent:Connect(function(player, )
end)
The script i need help with making (this is in starter player scripts):
local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")
local red_block = workspace.Blocks.RedBlocks:GetChildren()
local blue_block = workspace.Blocks.BlueBlocks:GetChildren()
remoteEvent:FireServer(function()
end)
You need to create the part in ServerScript ( If you want it to show on everyone ) because the LocalScript only affect the person that had the same LocalScript ( If you store it inside of StarterPlayerScripts or idk ).
Aight, you will need to change the LocalScript to ServerScript but you will probably gonna use the old one still for making the shadow_block to show on the player and the snap one
No, your local script must be local, only you must pass the following arguments to the server: coordinates, part, and then when you receive this information and process it (check), you do the same as on the client (clone, change position and parent). (I recommend using CFrame and not Position)
--localscript
mouse.Button1Down:Connect(function()
if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
remote:FireServer("blueBlock", shadow_block.Position)
end
end)
--serverscript
remote.OnServerEvent:Connect(function(plr, block, position)
--code to secure you remote...
local clone = game.ReplicatedStorage:WaitForChild(block):Clone()
clone.Parent = workspace.Blocks.BlueBlocks
clone.Position = Vector3.new(position)
end)
---------------------------------------------VARIBLES-------------------------------------------------
local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")
local runService = game:GetService("RunService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 1.5
local blueBlock = game.ReplicatedStorage:WaitForChild("BlueBlock")
local shadow_block = blueBlock:Clone(); shadow_block.Transparency = .5; shadow_block.Parent = workspace.Blocks.ShadowBlocks; shadow_block.CanCollide = false
if shadow_block.CanCollide == true then
print("BRUH")
end
mouse.TargetFilter = shadow_block
---------------------------------------------FUNCTIONS-------------------------------------------------
function snapToGrid(x)
return math.floor(x/grid + 0.5)*grid
end
function calculateY(toP, toS, oS)
return (toP + toS * 0.5) + oS * 0.5
end
runService.RenderStepped:Connect(function()
if mouse.Target ~= nil then
shadow_block.Position = Vector3.new(snapToGrid(mouse.Hit.Position.X), calculateY(mouse.Target.Position.Y, mouse.Target.Size.Y, blueBlock.Size.Y), snapToGrid(mouse.Hit.Position.Z))
end
end)
tool.Activated:Connect(function()
if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
remoteEvent:FireServer("blueBlock", shadow_block.Position)
print("script is working")
end
end)
runService.RenderStepped:Connect(function()
if tool:FindFirstAncestorWhichIsA("Model") ~= player.Character then
shadow_block.Transparency = 1
end
end)
runService.RenderStepped:Connect(function()
if tool:FindFirstAncestorWhichIsA("Model") == player.Character then
shadow_block.Transparency = 0.5
end
end)
But when I start the game, and i try to place a block, the blueblock in replicatedstorage disappears. And then (obviously), it gives me a infinite yield, since it doesn’t exist anymore. PLEASE HELP