Hello Developers!
(This is my first topic creation, so please excuse any mistakes! )
In the past few days, I have been trying to learn how to script, and create simple functions using scripts, which has been going somewhat well. My main goal is to create a roleplay facility game for my own benefit in a private roleplay group. One of the many tasks of making a roleplaying game is to create placeable items, which is something I do not have the knowledge of making on my own.
I’ve made the decision of looking at how to make it online, using different online resources, which hasn’t been going very well at least. I have been trying multiple methods, tutorials and resources, and not a single one has worked out fully.
The one that has been the closest to success is one I found online. I’ll provide the steps of said source here. This is where I require feedback & support. I am unable to locate where an issue may be, so I am reaching out to more experienced developers/scripters for assistance.
Steps/Additions made/added to create said “placement system”:
- Setup #1 (Object Folder)
- Setup #2 (ServerScriptService “Placement-Server”)
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")
PlacementEvent.OnServerEvent:Connect(function(Player, PreviewObject, ObjectCFrame)
local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
Object.SetPrimaryPartCFrame(ObjectCFrame)
Object.Parent = game.Workspace
end)
- Setup #3 (GUI and LocalScript “Placement-Handler”)
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local Frame = script.Parent:WaitForChild("Frame")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local PlacingObject = false
local RotatingObject = false
for i, Button in pairs(Frame:GetChildren()) do
if Button:IsA("TextButton") then
Button.MouseButton1Click:Connect(function()
if PlacingObject == false then
PlacingObject = true
Frame.Visible = false
local RotationAmount = 0
local PreviewObject = ObjectFolder:FindFirstChild(Button.Name):Clone()
PreviewObject.Parent = game.Workspace
for i, Parts in pairs(PreviewObject:GetDescendants()) do
if Parts:IsA("BasePart") then
Parts.Transparency = .5
Parts.CanCollide = false
end
end
UserInputService.InputBegan:Connect(function(Key, GameProcessed)
if not GameProcessed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
while RotatingObject == true do
wait()
RotationAmount += 2
end
end
end
end)
UserInputService.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
Mouse.TargetFilter = PreviewObject
if PreviewObject:FindFirstChild("MainPart") then
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X, Mouse.Hit.Position.Y + PreviewObject.PrimaryPart.Size.Y/2, Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0, math.rad(RotationAmount), 0)
PreviewObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)
end
end
end)
Mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(PreviewObject.Name, PreviewObject.PrimaryPart.CFrame)
Frame.Visible = true
PreviewObject:Destroy()
end
end)
end
end)
end
end
- Setup #4 (Event)
So this is the basic outline of what the tutorial asked me to follow/recreate. As I mentioned before, the GUI works, clicking a button hides it and places the Outline Part and the placeable on to your mouse, but when you click, everything disappears, and the GUI returns to a normal state.
I’ve tried digging into the script, but my little scripting knowledge did not help, so I came here to look after experienced support!
Any kind of assistance and support would be very appreciated, and if you have any other things I should improve on the above, please let me know!
-Thank you!