Attempt to index nil with 'Name'

The code below on line number 7 gives an "attempt to index nil with ‘Name’ error when I collide with the part, which I assume means that the value of player is nil. However printing player.Name directly does not error and does return my player name.

How would I go about fixing that line?

local parent = script.Parent


local function MultiChange(otherPart)
	local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)

	local strengthPlaceMulti = game.ServerStorage.RemoteData[player.Name].StrengthPlaceMulti.Value

	print(player.Name)

	strengthPlaceMulti = 10
end

parent.Touched:Connect(MultiChange)

Just add an if statement. You cannot control what touches the part so make sure you add checks

 if Player then -- Check
1 Like