I am attempting to make a “build system”, the camera will go above the players plot / road so they can build.
LOCAL SCRIPT:
-- // Variables
-- // Game Folders
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedScriptService = game:GetService("ReplicatedScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local StarterPack = game:GetService("StarterPack")
local StarterPlayer = game:GetService("StarterPlayer")
local Teams = game:GetService("Teams")
-- // Game Services
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
-- // Game Parts
local RoadFolder = game.Workspace:FindFirstChild("Roads")
local Paper = ReplicatedStorage.PlacementSystemFolder.Paper
local PlacePaper = ReplicatedStorage:WaitForChild("Paper", 500)
-- // Information
local OrderedRoad = nil
local IsPlacing = false
local Placed = false
local PosGood = false
local BuildModeActive = false
local Camera = game.Workspace.CurrentCamera
-- // Player Handling
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RegSpeed = Character:WaitForChild("Humanoid", 500).WalkSpeed
local RegJump = Character:WaitForChild("Humanoid", 500).JumpPower
local Mouse = Player:GetMouse()
local function CheckForOwnership(Player)
for _,Roads in pairs(RoadFolder:GetDescendants() ) do -- or RoadSimDataStore:GetAsync("RoadData")[Roads.Parent.Parent.Name]) do -- temp, fix datastore thing later
if Roads:IsA("StringValue") then
if Roads.Value == Player then
OrderedRoad = Roads.Parent.Parent
return OrderedRoad
end
end
end
end
-- // Script
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.N and BuildModeActive == false then
CheckForOwnership(Player.Name)
print("local script listening >:(")
if OrderedRoad == nil then
return warn("You do not own a road!")
else
local ToRoadTween = TweenService:Create(
Camera,
TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
{
CFrame = OrderedRoad.CameraPart.CFrame,
Focus = OrderedRoad.Road.CFrame
}
)
Camera.CameraType = Enum.CameraType.Scriptable
ToRoadTween:Play()
BuildModeActive = true
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
local ClientPaper = Paper:Clone()
IsPlacing = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
ClientPaper.Material = ("Neon")
ClientPaper.Transparency = (0.6)
ClientPaper.CanCollide = false
ClientPaper.Parent = game.Workspace
RunService.RenderStepped:Connect(function()
if not Character then
return
end
local MouseRay = Mouse.UnitRay
local CastRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 1000)
local IgnoreList = {ClientPaper, Character}
local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(CastRay, IgnoreList)
if Hit:IsDescendantOf(RoadFolder) then
PosGood = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
else
PosGood = false
ClientPaper.BrickColor = BrickColor.new("Bright red")
end
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
local PaperPosition = ClientPaper.CFrame
Placed = PlacePaper:InvokeServer(PaperPosition)
if Placed == true then
IsPlacing = false
ClientPaper:Destroy()
end
end
end)
end)
end
end
end)
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.N and BuildModeActive == true then
BuildModeActive = false
Character.Humanoid.WalkSpeed = RegSpeed
Character.Humanoid.JumpPower = RegJump
end
end)
It does not print anything.
SERVER SCRIPT:
-- // Variables
-- // Game Folders
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedScriptService = game:GetService("ReplicatedScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local StarterPack = game:GetService("StarterPack")
local StarterPlayer = game:GetService("StarterPlayer")
local Teams = game:GetService("Teams")
-- // Game Parts
local Paper = ReplicatedStorage.PlacementSystemFolder:FindFirstChild("Paper")
local RoadFolder = game.Workspace:FindFirstChild("Roads")
local PlacePaper = ReplicatedStorage:WaitForChild("PlacePaper", 500)
PlacePaper.OnServerInvoke = function(Player, PaperPosition)
local Placed = false
local ServerPaper = Paper:Clone()
if ServerPaper then
ServerPaper.CFrame = PaperPosition
ServerPaper.Parent = game.Workspace
Placed = true
else
Placed = false
end
end
This is suppose to move the player’s camera and then create a part and let them move it. When they click it is suppose to invoke the server and create a new part.
Hmm, it seems it is erroring here, I have no idea why…
local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(CastRay, IgnoreList)
if Hit:IsDescendantOf(RoadFolder) then
PosGood = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
else
PosGood = false
ClientPaper.BrickColor = BrickColor.new("Bright red")
end
I am attempting to check if the mouse’s position is on a part inside the RoadFolder variable.
local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(CastRay, IgnoreList)
if Hit and Hit:IsDescendantOf(RoadFolder) then
PosGood = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
else
PosGood = false
ClientPaper.BrickColor = BrickColor.new("Bright red")
end
That seems to of fixed it although it does not work how I was planning, when I press N, it tweens my camera but I have to press it again for a note to appear, and even then I cannot move my note.
(I am spamming N for it to stay shown, if I click while it is being shown it will create a note though, I think I could use debounce to fix this.)
(Ignore my mouse, it does this when recording a Gyazo GIF for some reason.)
-- // Variables
-- // Game Folders
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedScriptService = game:GetService("ReplicatedScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local StarterPack = game:GetService("StarterPack")
local StarterPlayer = game:GetService("StarterPlayer")
local Teams = game:GetService("Teams")
-- // Game Services
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
-- // Game Parts
local RoadFolder = game.Workspace:FindFirstChild("Roads")
local Paper = ReplicatedStorage.PlacementSystemFolder.Paper
local PlacePaper = ReplicatedStorage:FindFirstChild("PlacePaper")
-- // Information
local OrderedRoad = nil
local IsPlacing = false
local Placed = false
local PosGood = false
local BuildModeActive = false
local Camera = game.Workspace.CurrentCamera
-- // Player Handling
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RegSpeed = Character:WaitForChild("Humanoid").WalkSpeed
local RegJump = Character:WaitForChild("Humanoid").JumpPower
local Mouse = Player:GetMouse()
local function CheckForOwnership(Player)
for _,Roads in pairs(RoadFolder:GetDescendants() ) do -- or RoadSimDataStore:GetAsync("RoadData")[Roads.Parent.Parent.Name]) do -- temp, fix datastore thing later
if Roads:IsA("StringValue") then
if Roads.Value == Player then
OrderedRoad = Roads.Parent.Parent
return OrderedRoad
end
end
end
end
-- // Script
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.N and BuildModeActive == false then
CheckForOwnership(Player.Name)
print("local script listening >:(")
if OrderedRoad == nil then
return warn("You do not own a road!")
else
local ToRoadTween = TweenService:Create(
Camera,
TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
{
CFrame = OrderedRoad.CameraPart.CFrame,
Focus = OrderedRoad.Road.CFrame
}
)
Camera.CameraType = Enum.CameraType.Scriptable
ToRoadTween:Play()
BuildModeActive = true
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
local ClientPaper = Paper:Clone()
IsPlacing = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
ClientPaper.Material = ("Neon")
ClientPaper.Transparency = (0.6)
ClientPaper.CanCollide = false
ClientPaper.Parent = game.Workspace
RunService.RenderStepped:Connect(function()
if not Character then
return
end
local MouseRay = Mouse.UnitRay
local CastRay = Ray.new(MouseRay.Origin, MouseRay.Direction * 1000)
local IgnoreList = {ClientPaper, Character}
local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(CastRay, IgnoreList)
if Hit and Hit:IsDescendantOf(RoadFolder) then
PosGood = true
ClientPaper.BrickColor = BrickColor.new("Bright green")
else
PosGood = false
ClientPaper.BrickColor = BrickColor.new("Bright red")
end
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
local PaperPosition = ClientPaper.CFrame
Placed = PlacePaper:InvokeServer(PaperPosition)
if Placed == true then
IsPlacing = false
ClientPaper:Destroy()
end
end
end)
end)
end
end
end)
-- this part wont work
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.N and BuildModeActive == true then
BuildModeActive = false
Character.Humanoid.WalkSpeed = RegSpeed
Character.Humanoid.JumpPower = RegJump
end
end)
Server Script:
-- // Variables
-- // Game Folders
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ReplicatedScriptService = game:GetService("ReplicatedScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local StarterPack = game:GetService("StarterPack")
local StarterPlayer = game:GetService("StarterPlayer")
local Teams = game:GetService("Teams")
-- // Game Parts
local Paper = ReplicatedStorage.PlacementSystemFolder:FindFirstChild("Paper")
local RoadFolder = game.Workspace:FindFirstChild("Roads")
local PlacePaper = ReplicatedStorage:WaitForChild("PlacePaper")
-- // Information
local OrderedRoad = nil
local IsPlacing = false
local PosGood = false
local Placed = false
PlacePaper.OnServerInvoke = function(Player, PaperPosition)
local Placed = false
local ServerPaper = Paper:Clone()
if ServerPaper then
ServerPaper.CFrame = PaperPosition
ServerPaper.Parent = game.Workspace
Placed = true
else
Placed = false
end
end