I am trying to make a script that places a part (The part’s name is particle) at the end of a raycast aka the RaycastResult’s Posititon (the RaycastResult’s name is raycast), but for some reason I get the error message “attempt to index nil with ‘Position’” which makes no sense, because RaycastResult Can’t be nil, as the “WallHit” event only fires when the raycast hits a wall. I have no idea why this happens.
script:
script.Parent.WallHit.OnServerEvent:Connect(function(Player, parthit, raycast)
local particle = game.ServerStorage.Debris.WallParticlePart:Clone()
local Particles = particle:GetChildren()
for i, part in pairs(Particles) do
if part.ClassName == "Script" then
else
part.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, parthit.Color),
ColorSequenceKeypoint.new(1, parthit.Color)
}
end
end
particle.Parent = workspace
particle.Position = raycast.Position -- <= where the error happens --
end)
script.Parent.WallHit.OnServerEvent:Connect(function(Player, parthit, raycast)
if raycast and raycast.Position then
local particle = game.ServerStorage.Debris.WallParticlePart:Clone()
local Particles = particle:GetChildren()
for i, part in pairs(Particles) do
if part.ClassName == "Script" then
else
part.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, parthit.Color),
ColorSequenceKeypoint.new(1, parthit.Color)
}
end
end
particle.Parent = workspace
particle.Position = raycast.Position
end
end)
Before, the part would appear, but only in the center of the map, but now it does not appear at all, which means that raycast is nil? But I have used raycast.Position in another script (the script where the raycast originates from) and it works just fine, but in this script it does not work. Maybe the RemoteEvent messes something up?
Can you post your function firing the RemoteEvent?
Remember that you don’t need to specify the player;
RemoteEvent:FireServer(parthit, raycast)
as opposed to:
RemoteEvent:FireServer(player, parthit, raycast)
Also remember that FireServer can’t replicate things to the server, so you can only send details/properties about things to the server such as raycast.Position rather than the instance ‘raycast’
and the one that puts the part at the end of the raycast to
script.Parent.WallHit.OnServerEvent:Connect(function(Player, parthit, raycast)
local particle = game.ServerStorage.Debris.WallParticlePart:Clone()
local Particles = particle:GetChildren()
for i, part in pairs(Particles) do
if part.ClassName == "Script" then
else
part.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, parthit.Color),
ColorSequenceKeypoint.new(1, parthit.Color)
}
end
end
particle.Parent = workspace
particle.Position = raycast
end)