Hello, new user here.
I have been tinkering with roblox scripting for a few weeks now and I have been trying to emulate the bee swarm style mining system (or rather pollen gathering system). right now I have a setup of raycasts to come from the players head in various directions and then detect the part they are hitting and then move the part down by a marginal amount as the flowers do in bee swarm. Everything I have done is from browsing the internet for hours upon hours to get this to work lol. As of right not it works, however its not perfect like it is in bee swarm. So to get to my question, is there a better way I could be doing this? Should I be using raycasting? Originally I was using onotouched, with an invisible "scoop" which would do the same onTouched as the rays with different shapes.
Again, I am very new to scripting and have been doing it for fun in my free time via watching videos, reading and just trying things out. So my code most certainly isn't pretty or perfect, just asking for some direction so I can continue this fun project! thanks
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- get the event from client side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local rayCastEvent1 = ReplicatedStorage:FindFirstChild("rayCastEvent1")
-- raycast function
local function rayCastEvent1(player,var)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character}
raycastParams.IgnoreWater = true
-- fire multiple raycast to move multiple parts of the mine at once
local raycastResult = workspace:Raycast(character.Head.Position, Vector3.new(0, -50, -20), raycastParams)
local raycastResult2 = workspace:Raycast(character.Head.Position, Vector3.new(0, -100, 0), raycastParams)
local raycastResult3 = workspace:Raycast(character.Head.Position, Vector3.new(0, -50, 20), raycastParams)
local raycastResult4 = workspace:Raycast(character.Head.Position, Vector3.new(20, -50, 0), raycastParams)
if raycastResult or raycastResult2 or raycastResult3 or raycastResult4 then
-- find parts hit by raycast
local hitPart, hitPosition = unpack({raycastResult.Instance.Parent, raycastResult.Position})
local hitPart2, hitPosition2 = unpack({raycastResult2.Instance.Parent, raycastResult2.Position})
local hitPart3, hitPosition3 = unpack({raycastResult3.Instance.Parent, raycastResult3.Position})
local hitPart4, hitPosition4 = unpack({raycastResult4.Instance.Parent, raycastResult4.Position})
-- set model# to part hit by each raycast
local model = hitPart
local model2 = hitPart2
local model3 = hitPart3
local model4 = hitPart4
wait()
-- find the child of the part hit since the part hit is the model
if hitPart.Parent or hitPart2.Parent or hitPart3.Parent or hitPart4.Parent == game.Workspace.mineParts then
hitPart.PrimaryPart = hitPart:FindFirstChild("aMinePart")
hitPart2.PrimaryPart = hitPart2:FindFirstChild("aMinePart")
hitPart3.PrimaryPart = hitPart3:FindFirstChild("aMinePart")
hitPart4.PrimaryPart = hitPart4:FindFirstChild("aMinePart")
-- move parts hit by ray with cframe
hitPart:SetPrimaryPartCFrame(hitPart:GetPrimaryPartCFrame()*CFrame.new(0,-.3,0))
hitPart2:SetPrimaryPartCFrame(hitPart2:GetPrimaryPartCFrame()*CFrame.new(0,-.3,0))
hitPart3:SetPrimaryPartCFrame(hitPart3:GetPrimaryPartCFrame()*CFrame.new(0,-.3,0))
hitPart4:SetPrimaryPartCFrame(hitPart4:GetPrimaryPartCFrame()*CFrame.new(0,-.3,0))
wait(5)
hitPart:SetPrimaryPartCFrame(hitPart:GetPrimaryPartCFrame()*CFrame.new(0,.3,0))
hitPart2:SetPrimaryPartCFrame(hitPart2:GetPrimaryPartCFrame()*CFrame.new(0,.3,0))
hitPart3:SetPrimaryPartCFrame(hitPart3:GetPrimaryPartCFrame()*CFrame.new(0,.3,0))
hitPart4:SetPrimaryPartCFrame(hitPart4:GetPrimaryPartCFrame()*CFrame.new(0,.3,0))
end
end
end
game.ReplicatedStorage.rayCastEvent1.OnServerEvent:Connect(rayCastEvent1)
end)
end)

1 comment
thank you very much for the in depth answer, I really didn't expect this! I dont have time to go over this tonight but I will attempt to implement this tomorrow and see where I can get with your practice questions as well. I really do appreciate it!