I am making a game where players can mine ores and gain money. I'm currently working on the mining part of the game. I have 2 events called Destroy (fired when a player finishes mining an ore) and Hit (fired when a player mines an ore). However, I've run into an error with the script that handles those 2 events. The error is "attempt to index function with 'OnServerEvent'" Here's the code:
local event = game.ReplicatedStorage.Events.Hit local event2 = game.ReplicatedStorage.Events.Destroy function frc(model) local children = model:GetChildren() local child = children[math.random(1, #children)] return child end event2.OnServerEvent:Connect(function(ore) --Error occurs here --ignore everything below this local pos local rot local hits = ore.Hits local newDecor if ore.Name == 'Ore' then newDecor = frc(game.ReplicatedStorage.DecorParts1):Clone() elseif ore.Name == 'Ore+' then newDecor = frc(game.ReplicatedStorage.DecorParts2):Clone() end if ore:FindFirstChild('Low') then pos = ore.Low.Position rot = ore.Low.Orientation ore.Low:Destroy() elseif ore:FindFirstChild('Medium') then pos = ore.Medium.Position rot = ore.Medium.Orientation ore.Medium:Destroy() elseif ore:FindFirstChild('High') then pos = ore.High.Position rot = ore.High.Orientation ore.High:Destroy() elseif ore:FindFirstChild('UltraHigh') then pos = ore.UltraHigh.Position rot = ore.UltraHigh.Orientation ore.UltraHigh:Destroy() end if newDecor.Name == 'Low' then ore.OreValue.Value = 5 hits.Value = 3 wait(30) elseif newDecor.Name == 'Medium' then ore.OreValue.Value = 15 hits.Value = 6 wait(60) elseif newDecor.Name == 'High' then ore.OreValue.Value = 35 hits.Value = 10 wait(180) elseif newDecor.Name == 'UltraHigh' then ore.OreValue.Value = 65 hits.Value = 15 wait(300) end newDecor.Parent = ore newDecor.Position = pos newDecor.Orientation = rot end)
Please help! This script is critical to the game and I have no idea why the error is occurring. Thanks for taking time to look over my question.
I'm pretty sure that it's because your event is name destroy. I've encountered this problem myself and I had used a remote event name destroy.