Hello,
I am currently making a survival game and recently, I have added a build system where you can add a Campfire, Crafting bench and a Wooden floor to the world. This does work, and it does clone it to workspace, however, the problem is that when I clone the model to workspace, if I'm near something like a tree, instead of spawning it on the ground it spawns it right on top of the tree, making it inaccessible, I'm not sure if it's something wrong with the script or if I'm missing something. Or maybe to have a model that is specifically made so you cannot use the model placer on
I have a LocalScript inside the tool:
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cursor = Player:GetMouse()
local off = false
local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local mat = Enum.Material.ForceField
local color = BrickColor.new("Artichoke")
local eq = false
local Remote = ReplicatedStorage:WaitForChild("WoodenfloorRemote")
local WoodenfloorTool = script.Parent
WoodenfloorTool.Activated:Connect(function(input, click)
Remote:FireServer(Cursor.Hit.Position)
WoodenfloorTool:Destroy()
workspace.WoodenfloorBrick:Destroy()
end)
script.Parent.Equipped:Connect(function()
if Cursor ~= nil then
eq = true
local gui = script.Parent.material:Clone()
script.Parent.UsedGui.Value = gui
gui.Parent = plr.PlayerGui
local clonnedbrick = game.ReplicatedStorage.WoodenfloorBrick:Clone()
Cursor.TargetFilter = clonnedbrick
clonnedbrick.Transparency = 0
clonnedbrick.Parent = workspace
while Cursor ~= nil do
clonnedbrick.Position = Cursor.Hit.Position + Vector3.new(0,2,0)
clonnedbrick.Material = mat
clonnedbrick.BrickColor = color
wait()
if off then
clonnedbrick:Destroy()
off = false
break
end
end
end
end)
script.Parent.Activated:Connect(function()
local pos = Cursor.Hit.Position + Vector3.new(0,2,0)
script.Parent.RemoteEvent:FireServer(pos,mat,color)
end)
script.Parent.Unequipped:Connect(function()
eq = false
off = true
plr.PlayerGui:FindFirstChild("material"):Destroy()
end)
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E and eq then
local f = math.random(1,5)
if f == 1 then
mat = Enum.Material.WoodPlanks
color = BrickColor.new("Br. yellowish orange")
end
if f == 2 then
mat = Enum.Material.Wood
color = BrickColor.new("Br. yellowish orange")
end
if f == 3 then
mat = Enum.Material.Concrete
color = BrickColor.new("Ghost grey")
end
if f == 4 then
mat = Enum.Material.Fabric
color = BrickColor.new("Really red")
end
if f == 5 then
mat = Enum.Material.Foil
color = BrickColor.new("Ghost grey")
end
script.Parent.UsedGui.Value.Mat.Text = tostring(mat)
end
end)
And also a ServerScript inside my tool:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,pos,mat,C)
local ServerStorage = game:GetService("ServerStorage")
local brick = ServerStorage:WaitForChild("Wooden Floor")
brick.Parent = workspace
brick.CanCollide = true
brick.Position = pos
brick.Name = plr.Name
brick.Material = mat
brick.BrickColor = C
local Remote = ReplicatedStorage:WaitForChild("WoodenfloorRemote")
Remote.OnServerEvent:Connect(function(player, position)
local ClonedWoodenFloor = WoodenFloor:Clone()
ClonedWoodenFloor.Parent = game:GetService("Workspace")
ClonedWoodenFloor:MoveTo(position)
end)
Along with a Remote in ReplicatedStorage named WoodenfloorRemote
And also a ServerScript in ServerScriptStorage which makes the model accessable:
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WoodenfFoor = ServerStorage:WaitForChild("Wooden Floor")
local Remote = ReplicatedStorage:WaitForChild("WoodenfloorRemote")
Remote.OnServerEvent:Connect(function(player, position)
local ClonedWoodenfFoor = WoodenfFoor:Clone()
ClonedWoodenfFoor.Parent = game:GetService("Workspace")
ClonedWoodenfFoor:MoveTo(position)
end)
I feel that building is a very important part of my game, and if the model was to spawn on top of something and make it inaccessible, it would break the whole entire game.
Is there any way to fix this?
If anybody could help, it would be very great and I would really appreciate it.
Thanks
