Now, I have two identical scripts (save for some testing prints) that are listening to the same remote event. they are both local scripts, and they are receiving a tool. However, one of the scripts is getting just the tool, none of its descendants. The other script is working just fine, getting the tool and all descendants. I tried a few different approaches but came up dry, and I give up.
Code for local scripts (one has some prints, but they make no difference as far as I can tell.):
RunService = game:GetService("RunService")
counter = 0
event = game.ReplicatedStorage.PreviewRequest
selected = false
local item
event.OnClientEvent:Connect(function(source, object)
if item then
item:Destroy()
end
if object.ClassName == "Tool" then
local parts = object:GetChildren()
item = Instance.new("Model")
for i = 1, #parts do
local part = parts[i]
if part.ClassName ~= "Script" and part.ClassName ~= "LocalScript" then
part.Parent = item
if part.Name == "Handle" then
item.PrimaryPart = part
end
end
end
object:Destroy()
else
item = object
end
item.Parent = script.Parent
item:SetPrimaryPartCFrame(CFrame.new())
camera = Instance.new("Camera")
camera.Parent = script.Parent
script.Parent.CurrentCamera = camera
radius = 5
center = Vector3.new()
rad, cos, sin = math.rad, math.cos, math.sin
selected = true
end)
while true do
if selected == true then
counter = counter + 1
camera.CFrame = CFrame.new(Vector3.new(center.X + radius*cos(rad(counter%1440)), 1, center.Z + radius*sin(rad(counter%1440))), Vector3.new())
end
RunService["Heartbeat"]:Wait()
end
Code for server script firing the client events:
event = game.ReplicatedStorage.PreviewRequest
event.OnServerEvent:Connect(function(player, source, item, gui)
print("Fired")
if item == "Campfire Kit" or item == "Heater Kit" then
item = game.ServerStorage.Entities[string.sub(item, 1, -5)]:Clone()
item.Parent = game.ReplicatedStorage
elseif item == "Deselect" then
item = false
else
item = game.ServerStorage[item]:Clone()
item.Parent = game.ReplicatedStorage
end
if item then
item = item:Clone()
item.Parent = gui
print(player, source, item)
event:FireClient(player, source, item)
end
end)
Code for local scripts firing to the server script:
event1 = game.ReplicatedStorage.PreviewRequest
event2 = game.ReplicatedStorage.DescriptionEvent
item = string.sub(script.Parent.Name, 1, -9)
button = script.Parent
selected = script.Parent.Parent.Selected
isSelected = false
button.MouseButton1Down:Connect(function()
print("Clicked", selected)
local gui = script.Parent.Parent.Parent.Parent.DescriptionFrame.WorkingViewportFrame
if isSelected == false and selected.Value == false then
event1:FireServer(script, item, gui)
event2:Fire(script, item, gui)
button.Style = "RobloxRoundDefaultButton"
isSelected = true
selected.Value = true
elseif isSelected == true and selected.Value == true then
event1:FireServer(script, "Deselect", gui)
event2:Fire(script, "Deselect", gui)
button.Style = "RobloxRoundDropdownButton"
isSelected = false
selected.Value = false
end
end)
Edit for relevant hierarchy: