Hey guys!
I have a problem,
the script here:
local script to trigger event.
local PRM = game:GetService("ProximityPromptService")
local attach = "Eotech"
game.Workspace.Scope.ProximityPrompt.Triggered:Connect(function()
for i,v in pairs(workspace:GetChildren()) do
local Check = v:FindFirstChild("ViewModel") -- finds the value in the model that has "viewmodel"
if Check then
print("Fired")
game.ReplicatedStorage.FireAttachmentEvent:FireServer(attach,v)
end
end
end)
The local script actually fires the event.
Server script to add the eotech.
game:GetService("ReplicatedStorage").FireAttachmentEvent.OnServerEvent:Connect(function(plr, AttachmentName, Model)
print("Recieve signal")
for i,v in pairs(game.ReplicatedFirst.Attachments:GetChildren()) do
print(v)
if v.Name == "Eotech" then
print("Checked - Server")
local attachment = v:Clone()
attachment.Parent = Model
print("Added")
if attachment.Type.Value == "Scope" then
print("Added Scope2")
attachment.Position = Model:WaitForChild("MainPart").BodyTopATT1.Position
local weld = Instance.new("Weld",Model.Mainpart)
weld.Part0 = Model:WaitForChild("MainPart")
weld.Part1 = attachment
end
end
end
end)
creates the error
ServerScriptService.Script:12: attempt to index nil with 'Mainpart' - Server - Script:10
08:55:43.042 Stack Begin - Studio
08:55:43.042 Script 'ServerScriptService.Script', Line 12- Studio - Script:10
08:55:43.042 Stack End - Studio
Im still stuck on this problem and its really hard to fix it.