Had a question about my "Placables" system breaking another script when a new item is placed?
PlacablesClient: Located inside of the "HammerToolGui" basic rundown is that this script waits for a player to click a button in the gui the corresponds to what item there trying to place. The script gets the model (and its parts) and creates a clone to provide the player with a visual on where there newly placed item will be. The script looks for the mouse position and other important stuff like that and sends it off to the server as soon as the player releases their left mouse button. The server receives this info and places the actual item accordingly. There's also a rotate function inside of this script but I don't think that's causing my problem so i wont go into detail. (I know its poorly written but I'm brand new)
001 | local PlaceEvent = game.ReplicatedStorage.PlaceableEvents.PlaceEvent |
002 | local ObjectFolder = game.ReplicatedStorage:WaitForChild( "PlaceableStorage" ) |
004 | local Player = game.Players.LocalPlayer |
005 | local Character = Player.Character or Player.CharacterAdded:Wait() |
006 | local HumanoidrootPart = Character:WaitForChild( "HumanoidRootPart" ) |
007 | local Mouse = Player:GetMouse() |
009 | local Frame = script.Parent.ItemList |
010 | local UIS = game:GetService( "UserInputService" ) |
011 | local RunService = game:GetService( "RunService" ) |
012 | local GUI = game.StarterGui.HammerToolGui.MainFrame |
014 | local PlacingObject = false |
015 | local RotatingObject = false |
016 | local maxPlacingDistance = 50 |
019 | for i, Button in pairs (Frame:GetChildren()) do |
021 | if Button:IsA( "TextButton" ) then |
023 | Button.MouseButton 1 Click:Connect( function () |
025 | local goodToPlace = false |
027 | if PlacingObject = = false then |
032 | local RotationAmount = 0 |
034 | local PreviewObject = ObjectFolder:FindFirstChild(Button.Name):Clone() |
035 | PreviewObject.Parent = game.Workspace.PlaceableThings |
038 | for i, Parts in pairs (PreviewObject:GetDescendants()) do |
040 | if Parts:IsA( "BasePart" ) then |
042 | Parts.Transparency = 0.5 |
043 | Parts.CanCollide = false |
045 | RunService.RenderStepped:Connect( function () |
046 | local mouseRay = Mouse.UnitRay |
047 | local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000 ) |
048 | local ignoreList = { PreviewObject } |
049 | local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList) |
051 | if hit and (hit:IsA( "Terrain" ) or hit.Name:lower() = = "terrain" ) and (HumanoidrootPart.Position - Parts.Position) .Magnitude < maxPlacingDistance then |
053 | Parts.BrickColor = BrickColor.new( "Forest green" ) |
056 | Parts.BrickColor = BrickColor.new( "Crimson" ) |
063 | UIS.InputBegan:Connect( function (Key, GameProcessed) |
065 | if not GameProcessed then |
067 | if Key.KeyCode = = Enum.KeyCode.R then |
069 | RotatingObject = true |
071 | while RotatingObject = = true do |
079 | UIS.InputEnded:Connect( function (Key) |
081 | if Key.KeyCode = = Enum.KeyCode.R then |
083 | RotatingObject = false |
087 | RunService.RenderStepped:Connect( function () |
089 | if PlacingObject = = true then |
091 | Mouse.TargetFilter = PreviewObject |
093 | if PreviewObject:FindFirstChild( "MainPart" ) then |
095 | local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X, Mouse.Hit.Position.Y + PreviewObject.PrimaryPart.Size.Y / 2 , Mouse.Hit.Position.Z) |
096 | local ObjectAngles = CFrame.Angles( 0 , math.rad(RotationAmount), 0 ) |
098 | PreviewObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles) |
103 | Mouse.Button 1 Up:Connect( function () |
105 | if PlacingObject = = true then |
106 | if goodToPlace = = true then |
108 | PlacingObject = false |
110 | for i, x in pairs (Player.PlayerGui.InventoryGui.Frame.Inventory.Items.Grid:GetChildren()) do |
111 | if x:IsA( "Frame" ) and x.Name = = Button.Name then |
117 | PlaceEvent:FireServer(PreviewObject.Name, PreviewObject.PrimaryPart.CFrame) |
120 | PreviewObject:Destroy() |
PickupManager: Located inside of "StarterPlayerScripts" basic rundown this script works in conjunction with another system (completely separate from placables system) my inventory system. The script waits for a player to get close enough to the item on the ground and then displays a gui based on that. The script then listens for the player to press the G key to "collect" the item.
01 | local function onInputEnded(input, mouse, player, pickupItemEvent) |
02 | if input.KeyCode = = Enum.KeyCode.G then |
03 | local target = mouse.Target |
04 | if target and target:FindFirstChild( "Pickable" ) then |
06 | local distanceFromItem = player:DistanceFromCharacter(item.Position) |
07 | if distanceFromItem < 7 then |
09 | print (item.Desc.Value) |
10 | pickupItemEvent:FireServer(item.Name, item.Desc.Value) |
11 | print ( "fired to server" ) |
18 | local function onInputChanged(input, mouse, pickupInfoGui) |
19 | local target = mouse.Target |
20 | if target and target:FindFirstChild( "Pickable" ) then |
22 | pickupInfoGui.Adornee = item |
23 | pickupInfoGui.ObjectName.Text = item.Name |
24 | pickupInfoGui.Enabled = true |
26 | pickupInfoGui.Adornee = nil |
27 | pickupInfoGui.Enabled = false |
31 | local UIS = game:GetService( "UserInputService" ) |
32 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
33 | local PickupItem = ReplicatedStorage.InvEvents.PickUpClient |
35 | local player = game.Players.LocalPlayer |
36 | local mouse = player:GetMouse() |
38 | local PlayerGui = player:WaitForChild( "PlayerGui" ) |
39 | local PickupInfoGui = PlayerGui:WaitForChild( "PickUpInfoGui" ) |
41 | UIS.InputChanged:Connect( function (input) |
42 | onInputChanged(input, mouse, PickupInfoGui) |
45 | UIS.InputEnded:Connect( function (input) |
46 | onInputEnded(input, mouse, player, PickupItem) |
So now that you have all of that information I can tell you about the actual problem. When I join the game and place one of the "placables" the game will no longer allow me to pick up items, the gui to pick things up wont even display (keep in mind these to scripts do not work in conjunction with each other in any way). What's strange is if the player dies they can pick up items again but again after a "placable" is placed the player can no longer pick up items.
Anyone have any ideas?